home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / ZSI / generate / containers.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2008-10-13  |  76.7 KB  |  2,440 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import types
  5. import warnings
  6. from utility import StringWriter, TextProtect, TextProtectAttributeName, GetPartsSubNames
  7. from utility import NamespaceAliasDict as NAD, NCName_to_ClassName as NC_to_CN
  8. import ZSI
  9. from ZSI.TC import _is_xsd_or_soap_ns
  10. from ZSI.wstools import XMLSchema, WSDLTools
  11. from ZSI.wstools.Namespaces import SCHEMA, SOAP, WSDL
  12. from ZSI.wstools.logging import getLogger as _GetLogger
  13. from ZSI.typeinterpreter import BaseTypeInterpreter
  14. from ZSI.generate import WSISpec, WSInteropError, Wsdl2PythonError, WsdlGeneratorError, WSDLFormatError
  15. ID1 = '    '
  16. ID2 = 2 * ID1
  17. ID3 = 3 * ID1
  18. ID4 = 4 * ID1
  19. ID5 = 5 * ID1
  20. ID6 = 6 * ID1
  21. KW = {
  22.     'ID1': ID1,
  23.     'ID2': ID2,
  24.     'ID3': ID3,
  25.     'ID4': ID4,
  26.     'ID5': ID5,
  27.     'ID6': ID6 }
  28. DEC = '_Dec'
  29. DEF = '_Def'
  30.  
  31. type_class_name = lambda n: '%s%s' % (NC_to_CN(n), DEF)
  32.  
  33. element_class_name = lambda n: '%s%s' % (NC_to_CN(n), DEC)
  34.  
  35. def IsRPC(item):
  36.     if not isinstance(item, WSDLTools.OperationBinding):
  37.         raise TypeError, 'IsRPC takes 1 argument of type WSDLTools.OperationBinding'
  38.     
  39.     soapbinding = item.getBinding().findBinding(WSDLTools.SoapBinding)
  40.     sob = item.findBinding(WSDLTools.SoapOperationBinding)
  41.     style = soapbinding.style
  42.     if sob is not None:
  43.         if not sob.style:
  44.             pass
  45.         style = soapbinding.style
  46.     
  47.     return style == 'rpc'
  48.  
  49.  
  50. def IsLiteral(item):
  51.     if not isinstance(item, WSDLTools.MessageRoleBinding):
  52.         raise TypeError, 'IsLiteral takes 1 argument of type WSDLTools.MessageRoleBinding'
  53.     
  54.     sbb = None
  55.     if item.type == 'input' or item.type == 'output':
  56.         sbb = item.findBinding(WSDLTools.SoapBodyBinding)
  57.     
  58.     if sbb is None:
  59.         raise ValueError, 'Missing soap:body binding.'
  60.     
  61.     return sbb.use == 'literal'
  62.  
  63.  
  64. def SetTypeNameFunc(func):
  65.     global type_class_name
  66.     type_class_name = func
  67.  
  68.  
  69. def SetElementNameFunc(func):
  70.     global element_class_name
  71.     element_class_name = func
  72.  
  73.  
  74. def GetClassNameFromSchemaItem(item, do_extended = False):
  75.     alias = NAD.getAlias(item.getTargetNamespace())
  76.     if item.isDefinition() is True:
  77.         return '%s.%s' % (alias, NC_to_CN('%s' % type_class_name(item.getAttributeName())))
  78.     
  79.  
  80.  
  81. def FromMessageGetSimpleElementDeclaration(message):
  82.     if len(message.parts) == 1 and message.parts[0].element is not None:
  83.         part = message.parts[0]
  84.         (nsuri, name) = part.element
  85.         wsdl = message.getWSDL()
  86.         types = wsdl.types
  87.         if types.has_key(nsuri) and types[nsuri].elements.has_key(name):
  88.             e = types[nsuri].elements[name]
  89.             if isinstance(e, XMLSchema.ElementDeclaration) is True and e.getAttribute('type'):
  90.                 typ = e.getAttribute('type')
  91.                 bt = BaseTypeInterpreter()
  92.                 ptype = bt.get_pythontype(typ[1], typ[0])
  93.                 return ptype
  94.             
  95.         
  96.     
  97.  
  98.  
  99. class AttributeMixIn:
  100.     attribute_typecode = 'self.attribute_typecode_dict'
  101.     built_in_refs = [
  102.         (SOAP.ENC, 'arrayType')]
  103.     
  104.     def _setAttributes(self, attributes):
  105.         atd = self.attribute_typecode
  106.         atd_list = formatted_attribute_list = []
  107.         if not attributes:
  108.             return formatted_attribute_list
  109.         
  110.         atd_list.append('# attribute handling code')
  111.         idx = 0
  112.         while idx < len(attributes):
  113.             a = attributes[idx]
  114.             idx += 1
  115.             if a.isWildCard() and a.isDeclaration():
  116.                 atd_list.append('%s[("%s","anyAttribute")] = ZSI.TC.AnyElement()' % (atd, SCHEMA.XSD3))
  117.                 continue
  118.             if a.isDeclaration():
  119.                 tdef = a.getTypeDefinition('type')
  120.                 if tdef is not None:
  121.                     tc = '%s.%s(None)' % (NAD.getAlias(tdef.getTargetNamespace()), self.mangle(type_class_name(tdef.getAttributeName())))
  122.                 else:
  123.                     t = a.getAttribute('type')
  124.                     
  125.                     try:
  126.                         tc = BTI.get_typeclass(t[1], t[0])
  127.                     except:
  128.                         tc = ZSI.TC.String
  129.  
  130.                     if tc is not None:
  131.                         tc = '%s()' % tc
  132.                     
  133.                 key = None
  134.                 if a.getAttribute('form') == 'qualified':
  135.                     key = '("%s","%s")' % (a.getTargetNamespace(), a.getAttribute('name'))
  136.                 elif a.getAttribute('form') == 'unqualified':
  137.                     key = '"%s"' % a.getAttribute('name')
  138.                 else:
  139.                     raise ContainerError, 'attribute form must be un/qualified %s' % a.getAttribute('form')
  140.                 atd_list.append('%s[%s] = %s' % (atd, key, tc))
  141.                 continue
  142.             if a.isReference() and a.isAttributeGroup():
  143.                 for ga in a.getAttributeGroup().getAttributeContent():
  144.                     attributes += (ga,)
  145.                 
  146.             if a.isReference():
  147.                 
  148.                 try:
  149.                     ga = a.getAttributeDeclaration()
  150.                 except XMLSchema.SchemaError:
  151.                     key = a.getAttribute('ref')
  152.                     self.logger.debug('No schema item for attribute ref (%s, %s)' % key)
  153.                     if key in self.built_in_refs:
  154.                         continue
  155.                     
  156.                     raise 
  157.  
  158.                 tp = None
  159.                 if ga is not None:
  160.                     tp = ga.getTypeDefinition('type')
  161.                     key = '("%s","%s")' % (ga.getTargetNamespace(), ga.getAttribute('name'))
  162.                 
  163.                 if ga is None:
  164.                     key = '("%s","%s")' % (a.getAttribute('ref').getTargetNamespace(), a.getAttribute('ref').getName())
  165.                     atd_list.append('%s[%s] = ZSI.TC.String()' % (atd, key))
  166.                 elif tp is None:
  167.                     
  168.                     try:
  169.                         (namespace, typeName) = ga.getAttribute('type')
  170.                     except TypeError:
  171.                         ex = None
  172.                         atd_list.append('%s[%s] = ZSI.TC.String()' % (atd, key))
  173.  
  174.                     atd_list.append('%s[%s] = %s()' % (atd, key, BTI.get_typeclass(typeName, namespace)))
  175.                 else:
  176.                     typeName = tp.getAttribute('name')
  177.                     namespace = tp.getTargetNamespace()
  178.                     alias = NAD.getAlias(namespace)
  179.                     key = '("%s","%s")' % (ga.getTargetNamespace(), ga.getAttribute('name'))
  180.                     atd_list.append('%s[%s] = %s.%s(None)' % (atd, key, alias, type_class_name(typeName)))
  181.             ga is None
  182.             raise TypeError, 'expecting an attribute: %s' % a.getItemTrace()
  183.         return formatted_attribute_list
  184.  
  185.  
  186.  
  187. class ContainerError(Exception):
  188.     pass
  189.  
  190.  
  191. class ContainerBase:
  192.     func_aname = staticmethod(TextProtectAttributeName)
  193.     logger = _GetLogger('ContainerBase')
  194.     
  195.     def __init__(self):
  196.         self.content = StringWriter('\n')
  197.         self._ContainerBase__setup = False
  198.         self.ns = None
  199.  
  200.     
  201.     def __str__(self):
  202.         return self.getvalue()
  203.  
  204.     
  205.     def mangle(self, s):
  206.         return TextProtect(s)
  207.  
  208.     
  209.     def write(self, s):
  210.         self.content.write(s)
  211.  
  212.     
  213.     def writeArray(self, a):
  214.         self.content.write('\n'.join(a))
  215.  
  216.     
  217.     def _setContent(self):
  218.         raise NotImplementedError, 'abstract method not implemented'
  219.  
  220.     
  221.     def getvalue(self):
  222.         if not self._ContainerBase__setup:
  223.             self._setContent()
  224.             self._ContainerBase__setup = True
  225.         
  226.         return self.content.getvalue()
  227.  
  228.     
  229.     def getNSAlias(self):
  230.         if self.ns is not None:
  231.             return NAD.getAlias(self.ns)
  232.         
  233.         raise ContainerError, 'no self.ns attr defined in %s' % self.__class__
  234.  
  235.     
  236.     def getNSModuleName(self):
  237.         if self.ns:
  238.             return NAD.getModuleName(self.ns)
  239.         
  240.         raise ContainerError, 'no self.ns attr defined in %s' % self.__class__
  241.  
  242.     
  243.     def getAttributeName(self, name):
  244.         if self.func_aname is None:
  245.             return name
  246.         
  247.         f = self.func_aname
  248.         return f(name)
  249.  
  250.  
  251.  
  252. class ServiceContainerBase(ContainerBase):
  253.     clientClassSuffix = 'SOAP'
  254.     logger = _GetLogger('ServiceContainerBase')
  255.  
  256.  
  257. class ServiceHeaderContainer(ServiceContainerBase):
  258.     imports = [
  259.         '\nimport urlparse, types',
  260.         'from ZSI.TCcompound import ComplexType, Struct',
  261.         'from ZSI import client',
  262.         'from ZSI.schema import GED, GTD',
  263.         'import ZSI']
  264.     logger = _GetLogger('ServiceHeaderContainer')
  265.     
  266.     def __init__(self, do_extended = False):
  267.         ServiceContainerBase.__init__(self)
  268.         self.basic = self.imports[:]
  269.         self.types = None
  270.         self.messages = None
  271.         self.extras = []
  272.         self.do_extended = do_extended
  273.  
  274.     
  275.     def setTypesModuleName(self, module):
  276.         self.types = module
  277.  
  278.     
  279.     def setMessagesModuleName(self, module):
  280.         self.messages = module
  281.  
  282.     
  283.     def appendImport(self, statement):
  284.         if type(statement) in (list, tuple):
  285.             self.extras += statement
  286.         else:
  287.             self.extras.append(statement)
  288.  
  289.     
  290.     def _setContent(self):
  291.         if self.messages:
  292.             self.write('from %s import *' % self.messages)
  293.         
  294.         if self.types:
  295.             self.write('from %s import *' % self.types)
  296.         
  297.         imports = self.basic[:]
  298.         imports += self.extras
  299.         self.writeArray(imports)
  300.  
  301.  
  302.  
  303. class ServiceLocatorContainer(ServiceContainerBase):
  304.     logger = _GetLogger('ServiceLocatorContainer')
  305.     
  306.     def __init__(self):
  307.         ServiceContainerBase.__init__(self)
  308.         self.serviceName = None
  309.         self.portInfo = []
  310.         self.locatorName = None
  311.         self.portMethods = []
  312.  
  313.     
  314.     def setUp(self, service):
  315.         self.serviceName = service.name
  316.         for p in service.ports:
  317.             
  318.             try:
  319.                 ab = p.getAddressBinding()
  320.             except WSDLTools.WSDLError:
  321.                 ex = None
  322.                 self.logger.warning('Skip port(%s), missing address binding' % p.name)
  323.                 continue
  324.  
  325.             if isinstance(ab, WSDLTools.SoapAddressBinding) is False:
  326.                 self.logger.warning('Skip port(%s), not a SOAP-1.1 address binding' % p.name)
  327.                 continue
  328.             
  329.             self.portInfo.append((NC_to_CN(p.name), NC_to_CN(p.getBinding().name), ab.location))
  330.         
  331.  
  332.     
  333.     def getLocatorName(self):
  334.         return self.locatorName
  335.  
  336.     
  337.     def getPortMethods(self):
  338.         return self.portMethods
  339.  
  340.     
  341.     def _setContent(self):
  342.         if not self.serviceName:
  343.             raise ContainerError, 'no service name defined!'
  344.         
  345.         self.serviceName = self.mangle(self.serviceName)
  346.         self.locatorName = '%sLocator' % self.serviceName
  347.         locator = [
  348.             '# Locator',
  349.             'class %s:' % self.locatorName]
  350.         self.portMethods = []
  351.         kwargs = KW.copy()
  352.         for port, bind, addr in self.portInfo:
  353.             method = 'get%s' % port
  354.             kwargs.update(dict(port = port, bind = bind, addr = addr, service = self.serviceName, suffix = self.clientClassSuffix, method = method))
  355.             locator += [
  356.                 '%(ID1)s%(port)s_address = "%(addr)s"' % kwargs,
  357.                 '%(ID1)sdef get%(port)sAddress(self):' % kwargs,
  358.                 '%(ID2)sreturn %(service)sLocator.%(port)s_address' % kwargs,
  359.                 '%(ID1)sdef %(method)s(self, url=None, **kw):' % kwargs,
  360.                 '%(ID2)sreturn %(bind)s%(suffix)s(url or %(service)sLocator.%(port)s_address, **kw)' % kwargs]
  361.             self.portMethods.append(method)
  362.         
  363.         self.writeArray(locator)
  364.  
  365.  
  366.  
  367. class ServiceOperationContainer(ServiceContainerBase):
  368.     logger = _GetLogger('ServiceOperationContainer')
  369.     
  370.     def __init__(self, useWSA = False, do_extended = False):
  371.         ServiceContainerBase.__init__(self)
  372.         self.useWSA = useWSA
  373.         self.do_extended = do_extended
  374.  
  375.     
  376.     def hasInput(self):
  377.         return self.inputName is not None
  378.  
  379.     
  380.     def hasOutput(self):
  381.         return self.outputName is not None
  382.  
  383.     
  384.     def isRPC(self):
  385.         return IsRPC(self.binding_operation)
  386.  
  387.     
  388.     def isLiteral(self, input = True):
  389.         msgrole = self.binding_operation.input
  390.         if input is False:
  391.             msgrole = self.binding_operation.output
  392.         
  393.         return IsLiteral(msgrole)
  394.  
  395.     
  396.     def isSimpleType(self, input = True):
  397.         if input is False:
  398.             return self.outputSimpleType
  399.         
  400.         return self.inputSimpleType
  401.  
  402.     
  403.     def getOperation(self):
  404.         return self.port.operations.get(self.name)
  405.  
  406.     
  407.     def getBOperation(self):
  408.         return self.port.get(self.name)
  409.  
  410.     
  411.     def getOperationName(self):
  412.         return self.name
  413.  
  414.     
  415.     def setUp(self, item):
  416.         if not isinstance(item, WSDLTools.OperationBinding):
  417.             raise TypeError, 'Expecting WSDLTools Operation instance'
  418.         
  419.         if not item.input:
  420.             raise WSDLFormatError('No <input/> in <binding name="%s"><operation name="%s">' % (item.getBinding().name, item.name))
  421.         
  422.         self.name = None
  423.         self.port = None
  424.         self.soapaction = None
  425.         self.inputName = None
  426.         self.outputName = None
  427.         self.inputSimpleType = None
  428.         self.outputSimpleType = None
  429.         self.inputAction = None
  430.         self.outputAction = None
  431.         self.port = port = item.getBinding().getPortType()
  432.         self._wsdl = item.getWSDL()
  433.         self.name = name = item.name
  434.         self.binding_operation = bop = item
  435.         self.soap_input_headers = None
  436.         self.soap_output_headers = None
  437.         op = port.operations.get(name)
  438.         if op is None:
  439.             raise WSDLFormatError('<portType name="%s"/> no match for <binding name="%s"><operation name="%s">' % (port.name, item.getBinding().name, item.name))
  440.         
  441.         soap_bop = bop.findBinding(WSDLTools.SoapOperationBinding)
  442.         if soap_bop is None:
  443.             raise SOAPBindingError, 'expecting SOAP Bindings'
  444.         
  445.         self.soapaction = soap_bop.soapAction
  446.         sbody = bop.input.findBinding(WSDLTools.SoapBodyBinding)
  447.         if not sbody:
  448.             raise SOAPBindingError('Missing <binding name="%s"><operation name="%s"><input><soap:body>' % (port.binding.name, bop.name))
  449.         
  450.         self.encodingStyle = None
  451.         if sbody.use == 'encoded':
  452.             self.encodingStyle = sbody.encodingStyle
  453.         
  454.         self.inputName = op.getInputMessage().name
  455.         self.inputSimpleType = FromMessageGetSimpleElementDeclaration(op.getInputMessage())
  456.         self.inputAction = op.getInputAction()
  457.         self.soap_input_headers = bop.input.findBindings(WSDLTools.SoapHeaderBinding)
  458.         if bop.output is not None:
  459.             sbody = bop.output.findBinding(WSDLTools.SoapBodyBinding)
  460.             if not item.output:
  461.                 raise WSDLFormatError, 'Operation %s, no match for output binding' % name
  462.             
  463.             self.outputName = op.getOutputMessage().name
  464.             self.outputSimpleType = FromMessageGetSimpleElementDeclaration(op.getOutputMessage())
  465.             self.outputAction = op.getOutputAction()
  466.             self.soap_output_headers = bop.output.findBindings(WSDLTools.SoapHeaderBinding)
  467.         
  468.  
  469.     
  470.     def _setContent(self):
  471.         kwstring = 'kw = {}'
  472.         tCheck = 'if isinstance(request, %s) is False:' % self.inputName
  473.         bindArgs = ''
  474.         if self.encodingStyle is not None:
  475.             bindArgs = 'encodingStyle="%s", ' % self.encodingStyle
  476.         
  477.         if self.useWSA:
  478.             wsactionIn = 'wsaction = "%s"' % self.inputAction
  479.             wsactionOut = 'wsaction = "%s"' % self.outputAction
  480.             bindArgs += 'wsaction=wsaction, endPointReference=self.endPointReference, '
  481.             responseArgs = ', wsaction=wsaction'
  482.         else:
  483.             wsactionIn = '# no input wsaction'
  484.             wsactionOut = '# no output wsaction'
  485.             responseArgs = ''
  486.         bindArgs += '**kw)'
  487.         if self.do_extended:
  488.             inputName = self.getOperation().getInputMessage().name
  489.             wrap_str = ''
  490.             partsList = self.getOperation().getInputMessage().parts.values()
  491.             
  492.             try:
  493.                 subNames = GetPartsSubNames(partsList, self._wsdl)
  494.             except TypeError:
  495.                 ex = None
  496.                 raise Wsdl2PythonError, 'Extended generation failure: only supports doc/lit, ' + 'and all element attributes (<message><part element=' + '"my:GED"></message>) must refer to single global ' + 'element declaration with complexType content.  ' + '\n\n**** TRY WITHOUT EXTENDED ****\n'
  497.  
  498.             args = []
  499.             for pa in subNames:
  500.                 args += pa
  501.             
  502.             for arg in args:
  503.                 wrap_str += '%srequest.%s = %s\n' % (ID2, self.getAttributeName(arg), self.mangle(arg))
  504.             
  505.             argsStr = ','.join(args)
  506.             if len(argsStr) > 1:
  507.                 argsStr = ', ' + argsStr
  508.             
  509.             method = [
  510.                 '%s# op: %s' % (ID1, self.getOperation().getInputMessage()),
  511.                 '%sdef %s(self%s):' % (ID1, self.name, argsStr),
  512.                 '\n%srequest = %s()' % (ID2, self.inputName),
  513.                 '%s' % wrap_str,
  514.                 '%s%s' % (ID2, kwstring),
  515.                 '%s%s' % (ID2, wsactionIn),
  516.                 '%sself.binding.Send(None, None, request, soapaction="%s", %s' % (ID2, self.soapaction, bindArgs)]
  517.         elif self.soap_input_headers:
  518.             method = [
  519.                 '%s# op: %s' % (ID1, self.name),
  520.                 '%sdef %s(self, request, soapheaders=(), **kw):' % (ID1, self.name),
  521.                 '%s%s' % (ID2, tCheck),
  522.                 '%sraise TypeError, "%%s incorrect request type" %% (%s)' % (ID3, 'request.__class__'),
  523.                 '%s%s' % (ID2, wsactionIn),
  524.                 '%s# TODO: Check soapheaders' % ID2,
  525.                 '%sself.binding.Send(None, None, request, soapaction="%s", soapheaders=soapheaders, %s' % (ID2, self.soapaction, bindArgs)]
  526.         else:
  527.             method = [
  528.                 '%s# op: %s' % (ID1, self.name),
  529.                 '%sdef %s(self, request, **kw):' % (ID1, self.name),
  530.                 '%s%s' % (ID2, tCheck),
  531.                 '%sraise TypeError, "%%s incorrect request type" %% (%s)' % (ID3, 'request.__class__'),
  532.                 '%s%s' % (ID2, wsactionIn),
  533.                 '%sself.binding.Send(None, None, request, soapaction="%s", %s' % (ID2, self.soapaction, bindArgs)]
  534.         if not self.outputName:
  535.             method.append('%s#check for soap, assume soap:fault' % (ID2,))
  536.             method.append('%sif self.binding.IsSOAP(): self.binding.Receive(None, **kw)' % (ID2,))
  537.             self.writeArray(method)
  538.             return None
  539.         
  540.         response = [
  541.             '%s%s' % (ID2, wsactionOut)]
  542.         if self.isRPC() and not self.isLiteral():
  543.             response.append('%stypecode = Struct(pname=None, ofwhat=%s.typecode.ofwhat, pyclass=%s.typecode.pyclass)' % (ID2, self.outputName, self.outputName))
  544.             response.append('%sresponse = self.binding.Receive(typecode%s)' % (ID2, responseArgs))
  545.         else:
  546.             response.append('%sresponse = self.binding.Receive(%s.typecode%s)' % (ID2, self.outputName, responseArgs))
  547.         if self.soap_output_headers:
  548.             sh = '['
  549.             for shb in self.soap_output_headers:
  550.                 shb.message
  551.                 shb.part
  552.                 
  553.                 try:
  554.                     msg = self._wsdl.messages[shb.message]
  555.                     part = msg.parts[shb.part]
  556.                     if part.element is not None:
  557.                         sh += 'GED%s,' % str(part.element)
  558.                     else:
  559.                         warnings.warn('skipping soap output header in Message "%s"' % str(msg))
  560.                 continue
  561.                 raise WSDLFormatError('failure processing output header typecodes, ' + 'could not find message "%s" or its part "%s"' % (shb.message, shb.part))
  562.                 continue
  563.  
  564.             
  565.             sh += ']'
  566.             if len(sh) > 2:
  567.                 response.append('%sself.soapheaders = self.binding.ps.ParseHeaderElements(%s)' % (ID2, sh))
  568.             
  569.         
  570.         if self.outputSimpleType:
  571.             response.append('%sreturn %s(response)' % (ID2, self.outputName))
  572.         elif self.do_extended:
  573.             partsList = self.getOperation().getOutputMessage().parts.values()
  574.             subNames = GetPartsSubNames(partsList, self._wsdl)
  575.             args = []
  576.             for pa in subNames:
  577.                 args += pa
  578.             
  579.             for arg in args:
  580.                 response.append('%s%s = response.%s' % (ID2, self.mangle(arg), self.getAttributeName(arg)))
  581.             
  582.             margs = ','.join(args)
  583.             response.append('%sreturn %s' % (ID2, margs))
  584.         else:
  585.             response.append('%sreturn response' % ID2)
  586.         method += response
  587.         self.writeArray(method)
  588.  
  589.  
  590.  
  591. class BindingDescription(ServiceContainerBase):
  592.     readerclass = None
  593.     writerclass = None
  594.     operationclass = ServiceOperationContainer
  595.     logger = _GetLogger('BindingDescription')
  596.     
  597.     def __init__(self, useWSA = False, do_extended = False, wsdl = None):
  598.         ServiceContainerBase.__init__(self)
  599.         self.useWSA = useWSA
  600.         self.rProp = None
  601.         self.operations = None
  602.         self.do_extended = do_extended
  603.         self._wsdl = wsdl
  604.  
  605.     
  606.     def setReaderClass(cls, className):
  607.         cls.readerclass = className
  608.  
  609.     setReaderClass = classmethod(setReaderClass)
  610.     
  611.     def setWriterClass(cls, className):
  612.         cls.writerclass = className
  613.  
  614.     setWriterClass = classmethod(setWriterClass)
  615.     
  616.     def setOperationClass(cls, className):
  617.         cls.operationclass = className
  618.  
  619.     setOperationClass = classmethod(setOperationClass)
  620.     
  621.     def setUp(self, item):
  622.         portType = item.getPortType()
  623.         self._kwargs = KW.copy()
  624.         self._kwargs['bind'] = NC_to_CN(item.name)
  625.         self.operations = []
  626.         self.rProp = portType.getResourceProperties()
  627.         soap_binding = item.findBinding(WSDLTools.SoapBinding)
  628.         if soap_binding is None:
  629.             raise Wsdl2PythonError, 'Binding(%s) missing WSDLTools.SoapBinding' % item.name
  630.         
  631.         for bop in item.operations:
  632.             soap_bop = bop.findBinding(WSDLTools.SoapOperationBinding)
  633.             if soap_bop is None:
  634.                 self.logger.warning('Skip Binding(%s) operation(%s) no SOAP Binding Operation' % (item.name, bop.name))
  635.                 continue
  636.             
  637.             if bop.input is not None:
  638.                 soapBodyBind = bop.input.findBinding(WSDLTools.SoapBodyBinding)
  639.                 if soapBodyBind is None:
  640.                     self.logger.warning('Skip Binding(%s) operation(%s) Bindings(%s) not supported' % (item.name, bop.name, bop.extensions))
  641.                     continue
  642.                 
  643.             
  644.             op = portType.operations.get(bop.name)
  645.             if op is None:
  646.                 raise Wsdl2PythonError, 'no matching portType/Binding operation(%s)' % bop.name
  647.             
  648.             c = self.operationclass(useWSA = self.useWSA, do_extended = self.do_extended)
  649.             c.setUp(bop)
  650.             self.operations.append(c)
  651.         
  652.  
  653.     
  654.     def _setContent(self):
  655.         if self.useWSA is True:
  656.             args = 'endPointReference=None, **kw'
  657.             epr = 'self.endPointReference = endPointReference'
  658.         else:
  659.             args = '**kw'
  660.             epr = '# no ws-addressing'
  661.         if self.rProp:
  662.             rp = 'kw.setdefault("ResourceProperties", ("%s","%s"))' % (self.rProp[0], self.rProp[1])
  663.         else:
  664.             rp = '# no resource properties'
  665.         kwargs = self._kwargs
  666.         kwargs.update(dict(suffix = self.clientClassSuffix, args = args, epr = epr, rp = rp, readerclass = self.readerclass, writerclass = self.writerclass))
  667.         methods = [
  668.             '# Methods',
  669.             'class %(bind)s%(suffix)s:' % kwargs,
  670.             '%(ID1)sdef __init__(self, url, %(args)s):' % kwargs,
  671.             '%(ID2)skw.setdefault("readerclass", %(readerclass)s)' % kwargs,
  672.             '%(ID2)skw.setdefault("writerclass", %(writerclass)s)' % kwargs,
  673.             '%(ID2)s%(rp)s' % kwargs,
  674.             '%(ID2)sself.binding = client.Binding(url=url, **kw)' % kwargs,
  675.             '%(ID2)s%(epr)s' % kwargs]
  676.         for op in self.operations:
  677.             methods += [
  678.                 op.getvalue()]
  679.         
  680.         self.writeArray(methods)
  681.  
  682.  
  683. ServiceOperationsClassContainer = BindingDescription
  684.  
  685. class MessageContainerInterface:
  686.     logger = _GetLogger('MessageContainerInterface')
  687.     
  688.     def setUp(self, port, soc, input):
  689.         raise NotImplementedError, 'Message container must implemented setUp.'
  690.  
  691.  
  692.  
  693. class ServiceDocumentLiteralMessageContainer(ServiceContainerBase, MessageContainerInterface):
  694.     logger = _GetLogger('ServiceDocumentLiteralMessageContainer')
  695.     
  696.     def __init__(self, do_extended = False):
  697.         ServiceContainerBase.__init__(self)
  698.         self.do_extended = do_extended
  699.  
  700.     
  701.     def setUp(self, port, soc, input):
  702.         content = self.content
  703.         simple = self._simple = soc.isSimpleType(soc.getOperationName())
  704.         name = soc.getOperationName()
  705.         operation = port.getBinding().getPortType().operations.get(name)
  706.         bop = port.getBinding().operations.get(name)
  707.         soapBodyBind = None
  708.         if input is True:
  709.             soapBodyBind = bop.input.findBinding(WSDLTools.SoapBodyBinding)
  710.             message = operation.getInputMessage()
  711.         else:
  712.             soapBodyBind = bop.output.findBinding(WSDLTools.SoapBodyBinding)
  713.             message = operation.getOutputMessage()
  714.         if len(message.parts) == 0:
  715.             raise Wsdl2PythonError, 'must specify part for doc/lit msg'
  716.         
  717.         p = None
  718.         if soapBodyBind.parts is not None:
  719.             if len(soapBodyBind.parts) > 1:
  720.                 raise Wsdl2PythonError, 'not supporting multiple parts in soap body'
  721.             
  722.             if len(soapBodyBind.parts) == 0:
  723.                 return None
  724.             
  725.             p = message.parts.get(soapBodyBind.parts[0])
  726.         
  727.         if not p:
  728.             pass
  729.         p = message.parts[0]
  730.         if p.type:
  731.             raise Wsdl2PythonError, 'no doc/lit suport for <part type>'
  732.         
  733.         if not p.element:
  734.             return None
  735.         
  736.         self.ns = p.element[0]
  737.         content.ns = p.element[0]
  738.         content.pName = p.element[1]
  739.         content.mName = message.name
  740.  
  741.     
  742.     def _setContent(self):
  743.         
  744.         try:
  745.             simple = self._simple
  746.         except AttributeError:
  747.             raise RuntimeError, 'call setUp first'
  748.  
  749.         kw = KW.copy()
  750.         kw.update(dict(message = self.content.mName, nsuri = self.content.ns, name = self.content.pName))
  751.         self.writeArray([
  752.             '%(message)s = GED("%(nsuri)s", "%(name)s").pyclass' % kw])
  753.  
  754.  
  755.  
  756. class ServiceRPCEncodedMessageContainer(ServiceContainerBase, MessageContainerInterface):
  757.     logger = _GetLogger('ServiceRPCEncodedMessageContainer')
  758.     
  759.     def setUp(self, port, soc, input):
  760.         name = soc.getOperationName()
  761.         bop = port.getBinding().operations.get(name)
  762.         op = port.getBinding().getPortType().operations.get(name)
  763.         self.input = input
  764.         self.op = op
  765.         self.bop = bop
  766.  
  767.     
  768.     def _setContent(self):
  769.         
  770.         try:
  771.             self.op
  772.         except AttributeError:
  773.             raise RuntimeError, 'call setUp first'
  774.  
  775.         pname = self.op.name
  776.         msgRole = self.op.input
  777.         msgRoleB = self.bop.input
  778.         if self.input is False:
  779.             pname = '%sResponse' % self.op.name
  780.             msgRole = self.op.output
  781.             msgRoleB = self.bop.output
  782.         
  783.         sbody = msgRoleB.findBinding(WSDLTools.SoapBodyBinding)
  784.         if not sbody or not (sbody.namespace):
  785.             raise WSInteropError, WSISpec.R2717
  786.         
  787.         encodingStyle = sbody.encodingStyle
  788.         namespace = sbody.namespace
  789.         tcb = MessageTypecodeContainer(tuple(msgRole.getMessage().parts.list))
  790.         ofwhat = '[%s]' % tcb.getTypecodeList()
  791.         pyclass = msgRole.getMessage().name
  792.         fdict = KW.copy()
  793.         fdict['nspname'] = sbody.namespace
  794.         fdict['pname'] = pname
  795.         fdict['pyclass'] = None
  796.         fdict['ofwhat'] = ofwhat
  797.         fdict['encoded'] = namespace
  798.         fdict['typecode'] = 'Struct(pname=("%(nspname)s","%(pname)s"), ofwhat=%(ofwhat)s, pyclass=%(pyclass)s, encoded="%(encoded)s")'
  799.         message = [
  800.             'class %(pyclass)s:',
  801.             '%(ID1)sdef __init__(self, **kw):',
  802.             '%(ID2)s"""Keyword parameters:']
  803.         idx = len(message)
  804.         for a, p in zip(tcb.getAttributeNames(), tcb.getParameterNames()):
  805.             message.insert(idx, '%(ID2)s' + p + ' -- part ' + p)
  806.             message.append('%(ID2)sself.' + a + ' =  kw.get("%s")' % p)
  807.             idx += 1
  808.         
  809.         message.insert(idx, '%(ID2)s"""')
  810.         if TypecodeContainerBase.metaclass is None:
  811.             fdict['pyclass'] = pyclass
  812.             fdict['typecode'] = fdict['typecode'] % fdict
  813.             message.append('%(pyclass)s.typecode = %(typecode)s')
  814.         else:
  815.             fdict['typecode'] = fdict['typecode'] % fdict
  816.             fdict['pyclass'] = pyclass
  817.             fdict['metaclass'] = TypecodeContainerBase.metaclass
  818.             message.insert(0, '_%(pyclass)sTypecode = %(typecode)s')
  819.             message.insert(2, '%(ID1)stypecode = _%(pyclass)sTypecode')
  820.             message.insert(3, '%(ID1)s__metaclass__ = %(metaclass)s')
  821.             message.append('%(pyclass)s.typecode.pyclass = %(pyclass)s')
  822.         self.writeArray((map,)((lambda l: l % fdict), message))
  823.  
  824.  
  825.  
  826. class ServiceRPCLiteralMessageContainer(ServiceContainerBase, MessageContainerInterface):
  827.     logger = _GetLogger('ServiceRPCLiteralMessageContainer')
  828.     
  829.     def setUp(self, port, soc, input):
  830.         name = soc.getOperationName()
  831.         bop = port.getBinding().operations.get(name)
  832.         op = port.getBinding().getPortType().operations.get(name)
  833.         self.op = op
  834.         self.bop = bop
  835.         self.input = input
  836.  
  837.     
  838.     def _setContent(self):
  839.         
  840.         try:
  841.             self.op
  842.         except AttributeError:
  843.             raise RuntimeError, 'call setUp first'
  844.  
  845.         operation = self.op
  846.         input = self.input
  847.         pname = operation.name
  848.         msgRole = operation.input
  849.         msgRoleB = self.bop.input
  850.         if input is False:
  851.             pname = '%sResponse' % operation.name
  852.             msgRole = operation.output
  853.             msgRoleB = self.bop.output
  854.         
  855.         sbody = msgRoleB.findBinding(WSDLTools.SoapBodyBinding)
  856.         if not sbody or not (sbody.namespace):
  857.             raise WSInteropError, WSISpec.R2717
  858.         
  859.         namespace = sbody.namespace
  860.         tcb = MessageTypecodeContainer(tuple(msgRole.getMessage().parts.list))
  861.         ofwhat = '[%s]' % tcb.getTypecodeList()
  862.         pyclass = msgRole.getMessage().name
  863.         fdict = KW.copy()
  864.         fdict['nspname'] = sbody.namespace
  865.         fdict['pname'] = pname
  866.         fdict['pyclass'] = None
  867.         fdict['ofwhat'] = ofwhat
  868.         fdict['encoded'] = namespace
  869.         fdict['typecode'] = 'Struct(pname=("%(nspname)s","%(pname)s"), ofwhat=%(ofwhat)s, pyclass=%(pyclass)s, encoded="%(encoded)s")'
  870.         message = [
  871.             'class %(pyclass)s:',
  872.             '%(ID1)sdef __init__(self, **kw):',
  873.             '%(ID2)s"""Keyword parameters:']
  874.         idx = len(message)
  875.         for a, p in zip(tcb.getAttributeNames(), tcb.getParameterNames()):
  876.             message.insert(idx, '%(ID2)s' + p + ' -- part ' + p)
  877.             message.append('%(ID2)sself.' + a + ' =  kw.get("%s")' % p)
  878.             idx += 1
  879.         
  880.         message.insert(idx, '%(ID2)s"""')
  881.         if TypecodeContainerBase.metaclass is None:
  882.             fdict['pyclass'] = pyclass
  883.             fdict['typecode'] = fdict['typecode'] % fdict
  884.             message.append('%(pyclass)s.typecode = %(typecode)s')
  885.         else:
  886.             fdict['typecode'] = fdict['typecode'] % fdict
  887.             fdict['pyclass'] = pyclass
  888.             fdict['metaclass'] = TypecodeContainerBase.metaclass
  889.             message.insert(0, '_%(pyclass)sTypecode = %(typecode)s')
  890.             message.insert(2, '%(ID1)stypecode = _%(pyclass)sTypecode')
  891.             message.insert(3, '%(ID1)s__metaclass__ = %(metaclass)s')
  892.             message.append('%(pyclass)s.typecode.pyclass = %(pyclass)s')
  893.         self.writeArray((map,)((lambda l: l % fdict), message))
  894.  
  895.  
  896. TypesContainerBase = ContainerBase
  897.  
  898. class TypesHeaderContainer(TypesContainerBase):
  899.     imports = [
  900.         'import ZSI',
  901.         'import ZSI.TCcompound',
  902.         'from ZSI.schema import LocalElementDeclaration, ElementDeclaration, TypeDefinition, GTD, GED']
  903.     logger = _GetLogger('TypesHeaderContainer')
  904.     
  905.     def _setContent(self):
  906.         self.writeArray(TypesHeaderContainer.imports)
  907.  
  908.  
  909. NamespaceClassContainerBase = TypesContainerBase
  910.  
  911. class NamespaceClassHeaderContainer(NamespaceClassContainerBase):
  912.     logger = _GetLogger('NamespaceClassHeaderContainer')
  913.     
  914.     def _setContent(self):
  915.         head = [
  916.             '#' * 30,
  917.             '# targetNamespace',
  918.             '# %s' % self.ns,
  919.             '#' * 30 + '\n',
  920.             'class %s:' % self.getNSAlias(),
  921.             '%stargetNamespace = "%s"' % (ID1, self.ns)]
  922.         self.writeArray(head)
  923.  
  924.  
  925.  
  926. class NamespaceClassFooterContainer(NamespaceClassContainerBase):
  927.     logger = _GetLogger('NamespaceClassFooterContainer')
  928.     
  929.     def _setContent(self):
  930.         foot = [
  931.             '# end class %s (tns: %s)' % (self.getNSAlias(), self.ns)]
  932.         self.writeArray(foot)
  933.  
  934.  
  935. BTI = BaseTypeInterpreter()
  936.  
  937. class TypecodeContainerBase(TypesContainerBase):
  938.     mixed_content_aname = 'text'
  939.     attributes_aname = 'attrs'
  940.     metaclass = None
  941.     lazy = False
  942.     logger = _GetLogger('TypecodeContainerBase')
  943.     
  944.     def __init__(self, do_extended = False, extPyClasses = None):
  945.         TypesContainerBase.__init__(self)
  946.         self.name = None
  947.         self.allOptional = False
  948.         self.mgContent = None
  949.         self.contentFlattened = False
  950.         self.elementAttrs = []
  951.         self.tcListElements = []
  952.         self.tcListSet = False
  953.         self.localTypes = []
  954.         self.parentClass = None
  955.         self.mixed = False
  956.         self.extraFlags = ''
  957.         self.attrComponents = None
  958.         self.do_extended = do_extended
  959.         if extPyClasses is None:
  960.             self.extPyClasses = { }
  961.         else:
  962.             self.extPyClasses = extPyClasses
  963.  
  964.     
  965.     def getvalue(self):
  966.         out = ContainerBase.getvalue(self)
  967.         for item in self.localTypes:
  968.             content = None
  969.             etp = item.content
  970.             qName = item.getAttribute('type')
  971.             if not qName:
  972.                 etp = item.content
  973.                 local = True
  974.             else:
  975.                 etp = item.getTypeDefinition('type')
  976.             if etp is None:
  977.                 if local is True:
  978.                     content = ElementLocalComplexTypeContainer(do_extended = self.do_extended)
  979.                 else:
  980.                     content = ElementSimpleTypeContainer()
  981.             elif etp.isLocal() is False:
  982.                 content = ElementGlobalDefContainer()
  983.             elif etp.isSimple() is True:
  984.                 content = ElementLocalSimpleTypeContainer()
  985.             elif etp.isComplex():
  986.                 content = ElementLocalComplexTypeContainer(do_extended = self.do_extended)
  987.             else:
  988.                 raise Wsdl2PythonError, 'Unknown element declaration: %s' % item.getItemTrace()
  989.             content.setUp(item)
  990.             out += '\n\n'
  991.             if self.parentClass:
  992.                 content.parentClass = '%s.%s' % (self.parentClass, self.getClassName())
  993.             else:
  994.                 content.parentClass = '%s.%s' % (self.getNSAlias(), self.getClassName())
  995.             for l in content.getvalue().split('\n'):
  996.                 if l:
  997.                     out += '%s%s\n' % (ID1, l)
  998.                     continue
  999.                 out += '\n'
  1000.             
  1001.             out += '\n\n'
  1002.         
  1003.         return out
  1004.  
  1005.     
  1006.     def getAttributeName(self, name):
  1007.         if self.func_aname is None:
  1008.             return name
  1009.         
  1010.         f = self.func_aname
  1011.         return f(name)
  1012.  
  1013.     
  1014.     def getMixedTextAName(self):
  1015.         return self.getAttributeName(self.mixed_content_aname)
  1016.  
  1017.     
  1018.     def getClassName(self):
  1019.         if not self.name:
  1020.             raise ContainerError, 'self.name not defined!'
  1021.         
  1022.         if not hasattr(self.__class__, 'type'):
  1023.             raise ContainerError, 'container type not defined!'
  1024.         
  1025.         if self.__class__.type == DEF:
  1026.             classname = type_class_name(self.name)
  1027.         elif self.__class__.type == DEC:
  1028.             classname = element_class_name(self.name)
  1029.         
  1030.         return self.mangle(classname)
  1031.  
  1032.     
  1033.     def hasExtPyClass(self):
  1034.         if self.name in self.extPyClasses:
  1035.             return True
  1036.         else:
  1037.             return False
  1038.  
  1039.     
  1040.     def getPyClass(self):
  1041.         if self.hasExtPyClass():
  1042.             classInfo = self.extPyClasses[self.name]
  1043.             return '.'.join(classInfo)
  1044.         
  1045.         return 'Holder'
  1046.  
  1047.     
  1048.     def getPyClassDefinition(self):
  1049.         kw = KW.copy()
  1050.         if self.hasExtPyClass():
  1051.             classInfo = self.extPyClasses[self.name]
  1052.             kw['classInfo'] = classInfo[0]
  1053.             return [
  1054.                 '%(ID3)simport %(classInfo)s' % kw]
  1055.         
  1056.         kw['pyclass'] = self.getPyClass()
  1057.         definition = []
  1058.         definition.append('%(ID3)sclass %(pyclass)s:' % kw)
  1059.         if self.metaclass is not None:
  1060.             kw['type'] = self.metaclass
  1061.             definition.append('%(ID4)s__metaclass__ = %(type)s' % kw)
  1062.         
  1063.         definition.append('%(ID4)stypecode = self' % kw)
  1064.         definition.append('%(ID4)sdef __init__(self):' % kw)
  1065.         definition.append('%(ID5)s# pyclass' % kw)
  1066.         self._setUpElements()
  1067.         for el in self.elementAttrs:
  1068.             kw['element'] = el
  1069.             definition.append('%(ID2)s%(element)s' % kw)
  1070.         
  1071.         definition.append('%(ID5)sreturn' % kw)
  1072.         if self.name is not None:
  1073.             kw['name'] = self.name
  1074.             definition.append('%(ID3)s%(pyclass)s.__name__ = "%(name)s_Holder"' % kw)
  1075.         
  1076.         return definition
  1077.  
  1078.     
  1079.     def nsuriLogic(self):
  1080.         if self.parentClass:
  1081.             return 'ns = %s.%s.schema' % (self.parentClass, self.getClassName())
  1082.         
  1083.         return 'ns = %s.%s.schema' % (self.getNSAlias(), self.getClassName())
  1084.  
  1085.     
  1086.     def schemaTag(self):
  1087.         if self.ns is not None:
  1088.             return 'schema = "%s"' % self.ns
  1089.         
  1090.         raise ContainerError, 'failed to set schema targetNamespace(%s)' % self.__class__
  1091.  
  1092.     
  1093.     def typeTag(self):
  1094.         if self.name is not None:
  1095.             return 'type = (schema, "%s")' % self.name
  1096.         
  1097.         raise ContainerError, 'failed to set type name(%s)' % self.__class__
  1098.  
  1099.     
  1100.     def literalTag(self):
  1101.         if self.name is not None:
  1102.             return 'literal = "%s"' % self.name
  1103.         
  1104.         raise ContainerError, 'failed to set element name(%s)' % self.__class__
  1105.  
  1106.     
  1107.     def getExtraFlags(self):
  1108.         if self.mixed:
  1109.             self.extraFlags += 'mixed=True, mixed_aname="%s", ' % self.getMixedTextAName()
  1110.         
  1111.         return self.extraFlags
  1112.  
  1113.     
  1114.     def simpleConstructor(self, superclass = None):
  1115.         if superclass:
  1116.             return '%s.__init__(self, **kw)' % superclass
  1117.         else:
  1118.             return 'def __init__(self, **kw):'
  1119.  
  1120.     
  1121.     def pnameConstructor(self, superclass = None):
  1122.         if superclass:
  1123.             return '%s.__init__(self, pname, **kw)' % superclass
  1124.         else:
  1125.             return 'def __init__(self, pname, **kw):'
  1126.  
  1127.     
  1128.     def _setUpElements(self):
  1129.         self.logger.debug('_setUpElements: %s' % self._item.getItemTrace())
  1130.         if hasattr(self, '_done'):
  1131.             return None
  1132.         
  1133.         self._done = True
  1134.         flat = []
  1135.         content = self.mgContent
  1136.         if type(self.mgContent) is not tuple:
  1137.             mg = self.mgContent
  1138.             if not mg.isModelGroup():
  1139.                 mg = mg.content
  1140.             
  1141.             content = mg.content
  1142.             if mg.isAll():
  1143.                 flat = content
  1144.                 content = []
  1145.             elif mg.isModelGroup() and mg.isDefinition():
  1146.                 mg = mg.content
  1147.                 content = mg.content
  1148.             
  1149.         
  1150.         idx = 0
  1151.         content = list(content)
  1152.         while idx < len(content):
  1153.             c = orig = content[idx]
  1154.             if c.isElement():
  1155.                 flat.append(c)
  1156.                 idx += 1
  1157.                 continue
  1158.             
  1159.             if c.isReference() and c.isModelGroup():
  1160.                 c = c.getModelGroupReference()
  1161.             
  1162.             if c.isDefinition() and c.isModelGroup():
  1163.                 c = c.content
  1164.             
  1165.             if c.isSequence() or c.isChoice():
  1166.                 begIdx = idx
  1167.                 endIdx = begIdx + len(c.content)
  1168.                 for i in range(begIdx, endIdx):
  1169.                     content.insert(i, c.content[i - begIdx])
  1170.                 
  1171.                 content.remove(orig)
  1172.                 continue
  1173.             
  1174.             raise ContainerError, 'unexpected schema item: %s' % c.getItemTrace()
  1175.         for c in flat:
  1176.             if c.isDeclaration() and c.isElement():
  1177.                 defaultValue = 'None'
  1178.                 parent = c
  1179.                 defs = []
  1180.                 while defs.count(parent) <= 1:
  1181.                     maxOccurs = parent.getAttribute('maxOccurs')
  1182.                     if maxOccurs == 'unbounded' or int(maxOccurs) > 1:
  1183.                         defaultValue = '[]'
  1184.                         break
  1185.                     
  1186.                     parent = parent._parent()
  1187.                     if not parent.isModelGroup():
  1188.                         break
  1189.                     
  1190.                     if parent.isReference():
  1191.                         parent = parent.getModelGroupReference()
  1192.                     
  1193.                     if parent.isDefinition():
  1194.                         parent = parent.content
  1195.                         defs.append(parent)
  1196.                         continue
  1197.                 if None == c.getAttribute('name') and c.isWildCard():
  1198.                     e = '%sself.%s = %s' % (ID3, self.getAttributeName('any'), defaultValue)
  1199.                 else:
  1200.                     e = '%sself.%s = %s' % (ID3, self.getAttributeName(c.getAttribute('name')), defaultValue)
  1201.                 self.elementAttrs.append(e)
  1202.                 continue
  1203.             
  1204.             if c.isReference():
  1205.                 e = '%sself._%s = None' % (ID3, self.mangle(c.getAttribute('ref')[1]))
  1206.                 self.elementAttrs.append(e)
  1207.                 continue
  1208.             
  1209.             raise ContainerError, 'unexpected item: %s' % c.getItemTrace()
  1210.         
  1211.  
  1212.     
  1213.     def _setTypecodeList(self):
  1214.         self.logger.debug('_setTypecodeList(%r): %s' % (self.mgContent, self._item.getItemTrace()))
  1215.         flat = []
  1216.         content = self.mgContent
  1217.         if type(content) is not tuple:
  1218.             mg = content
  1219.             if not mg.isModelGroup():
  1220.                 raise Wsdl2PythonErr('Expecting ModelGroup: %s' % mg.getItemTrace())
  1221.             
  1222.             self.logger.debug('ModelGroup(%r) contents(%r): %s' % (mg, mg.content, mg.getItemTrace()))
  1223.             if mg.isReference():
  1224.                 raise RuntimeError('Unexpected modelGroup reference: %s' % mg.getItemTrace())
  1225.             
  1226.             if mg.isDefinition():
  1227.                 mg = mg.content
  1228.             
  1229.             if mg.isAll():
  1230.                 flat = mg.content
  1231.                 content = []
  1232.             elif mg.isSequence():
  1233.                 content = mg.content
  1234.             elif mg.isChoice():
  1235.                 content = mg.content
  1236.             else:
  1237.                 raise RuntimeError('Unknown schema item')
  1238.         
  1239.         idx = 0
  1240.         content = list(content)
  1241.         self.logger.debug('content: %r' % content)
  1242.         while idx < len(content):
  1243.             c = orig = content[idx]
  1244.             if c.isElement():
  1245.                 flat.append(c)
  1246.                 idx += 1
  1247.                 continue
  1248.             
  1249.             if c.isReference() and c.isModelGroup():
  1250.                 c = c.getModelGroupReference()
  1251.             
  1252.             if c.isDefinition() and c.isModelGroup():
  1253.                 c = c.content
  1254.             
  1255.             if c.isSequence() or c.isChoice():
  1256.                 begIdx = idx
  1257.                 endIdx = begIdx + len(c.content)
  1258.                 for i in range(begIdx, endIdx):
  1259.                     content.insert(i, c.content[i - begIdx])
  1260.                 
  1261.                 content.remove(orig)
  1262.                 continue
  1263.             
  1264.             raise ContainerError, 'unexpected schema item: %s' % c.getItemTrace()
  1265.         self.logger.debug('flat: %r' % list(flat))
  1266.         for c in flat:
  1267.             tc = TcListComponentContainer()
  1268.             (min, max, nil) = self._getOccurs(c)
  1269.             min = None
  1270.             max = None
  1271.             maxOccurs = 1
  1272.             parent = c
  1273.             defs = []
  1274.             while defs.count(parent) <= 1:
  1275.                 max = parent.getAttribute('maxOccurs')
  1276.                 if max == 'unbounded':
  1277.                     maxOccurs = '"%s"' % max
  1278.                     break
  1279.                 
  1280.                 maxOccurs = int(max) * maxOccurs
  1281.                 parent = parent._parent()
  1282.                 if not parent.isModelGroup():
  1283.                     break
  1284.                 
  1285.                 if parent.isReference():
  1286.                     parent = parent.getModelGroupReference()
  1287.                 
  1288.                 if parent.isDefinition():
  1289.                     parent = parent.content
  1290.                     defs.append(parent)
  1291.                     continue
  1292.             del defs
  1293.             parent = c
  1294.             while None:
  1295.                 minOccurs = int(parent.getAttribute('minOccurs'))
  1296.                 if minOccurs == 0 or parent.isChoice():
  1297.                     minOccurs = 0
  1298.                     break
  1299.                 
  1300.                 parent = parent._parent()
  1301.                 if not parent.isModelGroup():
  1302.                     minOccurs = int(c.getAttribute('minOccurs'))
  1303.                     break
  1304.                 
  1305.                 if parent.isReference():
  1306.                     parent = parent.getModelGroupReference()
  1307.                 
  1308.                 if parent.isDefinition():
  1309.                     parent = parent.content
  1310.                     continue
  1311.                 continue
  1312.                 tc.setOccurs(minOccurs, maxOccurs, nil)
  1313.                 processContents = self._getProcessContents(c)
  1314.                 tc.setProcessContents(processContents)
  1315.                 if c.isDeclaration() and c.isElement():
  1316.                     global_type = c.getAttribute('type')
  1317.                     content = getattr(c, 'content', None)
  1318.                     if c.isLocal() and c.isQualified() is False:
  1319.                         tc.unQualified()
  1320.                     
  1321.                     if c.isWildCard():
  1322.                         tc.setStyleAnyElement()
  1323.                     elif global_type is not None:
  1324.                         tc.name = c.getAttribute('name')
  1325.                         ns = global_type[0]
  1326.                         if ns in SCHEMA.XSD_LIST:
  1327.                             tpc = BTI.get_typeclass(global_type[1], global_type[0])
  1328.                             tc.klass = tpc
  1329.                         else:
  1330.                             tc.setGlobalType(*global_type)
  1331.                         del ns
  1332.                     elif content is not None and content.isLocal() and content.isComplex():
  1333.                         tc.name = c.getAttribute('name')
  1334.                         tc.klass = 'self.__class__.%s' % element_class_name(tc.name)
  1335.                         tc.setStyleElementReference()
  1336.                         self.localTypes.append(c)
  1337.                     elif content is not None and content.isLocal() and content.isSimple():
  1338.                         tc.name = c.getAttribute('name')
  1339.                         tc.klass = 'self.__class__.%s' % element_class_name(tc.name)
  1340.                         tc.setStyleElementReference()
  1341.                         self.localTypes.append(c)
  1342.                     else:
  1343.                         raise ContainerError, 'unexpected item: %s' % c.getItemTrace()
  1344.                 elif c.isReference():
  1345.                     ref = c.getAttribute('ref')
  1346.                     tc.setStyleElementReference()
  1347.                     tc.setGlobalType(*ref)
  1348.                 else:
  1349.                     raise ContainerError, 'unexpected item: %s' % c.getItemTrace()
  1350.             self.tcListElements.append(tc)
  1351.         
  1352.  
  1353.     
  1354.     def getTypecodeList(self):
  1355.         if not self.tcListSet:
  1356.             self._setTypecodeList()
  1357.             self.tcListSet = True
  1358.         
  1359.         list = []
  1360.         for e in self.tcListElements:
  1361.             list.append(str(e))
  1362.         
  1363.         return ', '.join(list)
  1364.  
  1365.     
  1366.     def _getOccurs(self, e):
  1367.         nillable = e.getAttribute('nillable')
  1368.         if nillable == 'true':
  1369.             nillable = True
  1370.         else:
  1371.             nillable = False
  1372.         maxOccurs = e.getAttribute('maxOccurs')
  1373.         if maxOccurs == 'unbounded':
  1374.             maxOccurs = '"%s"' % maxOccurs
  1375.         
  1376.         minOccurs = e.getAttribute('minOccurs')
  1377.         if self.allOptional is True:
  1378.             minOccurs = '0'
  1379.             maxOccurs = '"unbounded"'
  1380.         
  1381.         return (minOccurs, maxOccurs, nillable)
  1382.  
  1383.     
  1384.     def _getProcessContents(self, e):
  1385.         processContents = e.getAttribute('processContents')
  1386.         return processContents
  1387.  
  1388.     
  1389.     def getBasesLogic(self, indent):
  1390.         
  1391.         try:
  1392.             prefix = NAD.getAlias(self.sKlassNS)
  1393.         except WsdlGeneratorError:
  1394.             ex = None
  1395.             raise 
  1396.  
  1397.         bases = []
  1398.         bases.append('if %s.%s not in %s.%s.__bases__:' % (NAD.getAlias(self.sKlassNS), type_class_name(self.sKlass), self.getNSAlias(), self.getClassName()))
  1399.         bases.append('%sbases = list(%s.%s.__bases__)' % (ID1, self.getNSAlias(), self.getClassName()))
  1400.         bases.append('%sbases.insert(0, %s.%s)' % (ID1, NAD.getAlias(self.sKlassNS), type_class_name(self.sKlass)))
  1401.         bases.append('%s%s.%s.__bases__ = tuple(bases)' % (ID1, self.getNSAlias(), self.getClassName()))
  1402.         s = ''
  1403.         for b in bases:
  1404.             s += '%s%s\n' % (indent, b)
  1405.         
  1406.         return s
  1407.  
  1408.  
  1409.  
  1410. class MessageTypecodeContainer(TypecodeContainerBase):
  1411.     logger = _GetLogger('MessageTypecodeContainer')
  1412.     
  1413.     def __init__(self, parts = None):
  1414.         TypecodeContainerBase.__init__(self)
  1415.         self.mgContent = parts
  1416.  
  1417.     
  1418.     def _getOccurs(self, e):
  1419.         minOccurs = maxOccurs = '1'
  1420.         nillable = True
  1421.         return (minOccurs, maxOccurs, nillable)
  1422.  
  1423.     
  1424.     def _setTypecodeList(self):
  1425.         self.logger.debug('_setTypecodeList: %s' % str(self.mgContent))
  1426.         for p in self.mgContent:
  1427.             (min, max, nil) = self._getOccurs(p)
  1428.             if p.element:
  1429.                 raise WSInteropError, WSISpec.R2203
  1430.             elif p.type:
  1431.                 (nsuri, name) = p.type
  1432.                 tc = RPCMessageTcListComponentContainer(qualified = False)
  1433.                 tc.setOccurs(min, max, nil)
  1434.                 tc.name = p.name
  1435.                 if nsuri in [
  1436.                     SOAP.ENC] + SCHEMA.XSD_LIST:
  1437.                     tpc = BTI.get_typeclass(name, nsuri)
  1438.                     tc.klass = tpc
  1439.                 else:
  1440.                     tc.klass = '%s.%s' % (NAD.getAlias(nsuri), type_class_name(name))
  1441.             else:
  1442.                 raise ContainerError, 'part must define an element or type attribute'
  1443.             self.tcListElements.append(tc)
  1444.         
  1445.  
  1446.     
  1447.     def getTypecodeList(self):
  1448.         if not self.tcListSet:
  1449.             self._setTypecodeList()
  1450.             self.tcListSet = True
  1451.         
  1452.         list = []
  1453.         for e in self.tcListElements:
  1454.             list.append(str(e))
  1455.         
  1456.         return ', '.join(list)
  1457.  
  1458.     
  1459.     def getAttributeNames(self):
  1460.         return (map,)((lambda e: self.getAttributeName(e.name)), self.tcListElements)
  1461.  
  1462.     
  1463.     def getParameterNames(self):
  1464.         return map((lambda e: e.name), self.tcListElements)
  1465.  
  1466.     
  1467.     def setParts(self, parts):
  1468.         self.mgContent = parts
  1469.  
  1470.  
  1471.  
  1472. class TcListComponentContainer(ContainerBase):
  1473.     logger = _GetLogger('TcListComponentContainer')
  1474.     
  1475.     def __init__(self, qualified = True):
  1476.         ContainerBase.__init__(self)
  1477.         self.qualified = qualified
  1478.         self.name = None
  1479.         self.klass = None
  1480.         self.global_type = None
  1481.         self.min = None
  1482.         self.max = None
  1483.         self.nil = None
  1484.         self.style = None
  1485.         self.setStyleElementDeclaration()
  1486.  
  1487.     
  1488.     def setOccurs(self, min, max, nil):
  1489.         self.min = min
  1490.         self.max = max
  1491.         self.nil = nil
  1492.  
  1493.     
  1494.     def setProcessContents(self, processContents):
  1495.         self.processContents = processContents
  1496.  
  1497.     
  1498.     def setGlobalType(self, namespace, name):
  1499.         self.global_type = (namespace, name)
  1500.  
  1501.     
  1502.     def setStyleElementDeclaration(self):
  1503.         self.style = 'standard'
  1504.  
  1505.     
  1506.     def setStyleElementReference(self):
  1507.         self.style = 'ref'
  1508.  
  1509.     
  1510.     def setStyleAnyElement(self):
  1511.         self.name = 'any'
  1512.         self.style = 'anyElement'
  1513.  
  1514.     
  1515.     def unQualified(self):
  1516.         self.qualified = False
  1517.  
  1518.     
  1519.     def _getOccurs(self):
  1520.         return 'minOccurs=%s, maxOccurs=%s, nillable=%s' % (self.min, self.max, self.nil)
  1521.  
  1522.     
  1523.     def _getProcessContents(self):
  1524.         return 'processContents="%s"' % self.processContents
  1525.  
  1526.     
  1527.     def _getvalue(self):
  1528.         kw = {
  1529.             'occurs': self._getOccurs(),
  1530.             'aname': self.getAttributeName(self.name),
  1531.             'klass': self.klass,
  1532.             'lazy': TypecodeContainerBase.lazy,
  1533.             'typed': 'typed=False',
  1534.             'encoded': 'encoded=kw.get("encoded")' }
  1535.         gt = self.global_type
  1536.         if gt is not None:
  1537.             (kw['nsuri'], kw['type']) = gt
  1538.         
  1539.         if self.style == 'standard':
  1540.             kw['pname'] = '"%s"' % self.name
  1541.             if self.qualified is True:
  1542.                 kw['pname'] = '(ns,"%s")' % self.name
  1543.             
  1544.             if gt is None:
  1545.                 return '%(klass)s(pname=%(pname)s, aname="%(aname)s", %(occurs)s, %(typed)s, %(encoded)s)' % kw
  1546.             
  1547.             return 'GTD("%(nsuri)s","%(type)s",lazy=%(lazy)s)(pname=%(pname)s, aname="%(aname)s", %(occurs)s, %(typed)s, %(encoded)s)' % kw
  1548.         
  1549.         if self.style == 'ref':
  1550.             if gt is None:
  1551.                 return '%(klass)s(%(occurs)s, %(encoded)s)' % kw
  1552.             
  1553.             return 'GED("%(nsuri)s","%(type)s",lazy=%(lazy)s, isref=True)(%(occurs)s, %(encoded)s)' % kw
  1554.         
  1555.         kw['process'] = self._getProcessContents()
  1556.         if self.style == 'anyElement':
  1557.             return 'ZSI.TC.AnyElement(aname="%(aname)s", %(occurs)s, %(process)s)' % kw
  1558.         
  1559.         raise RuntimeError, 'Must set style for typecode list generation'
  1560.  
  1561.     
  1562.     def __str__(self):
  1563.         return self._getvalue()
  1564.  
  1565.  
  1566.  
  1567. class RPCMessageTcListComponentContainer(TcListComponentContainer):
  1568.     logger = _GetLogger('RPCMessageTcListComponentContainer')
  1569.     
  1570.     def __init__(self, qualified = True, encoded = None):
  1571.         TcListComponentContainer.__init__(self, qualified = qualified)
  1572.         self._encoded = encoded
  1573.  
  1574.     
  1575.     def _getvalue(self):
  1576.         encoded = self._encoded
  1577.         if encoded is not None:
  1578.             encoded = '"%s"' % self._encoded
  1579.         
  1580.         if self.style == 'standard':
  1581.             pname = '"%s"' % self.name
  1582.             if self.qualified is True:
  1583.                 pname = '(ns,"%s")' % self.name
  1584.             
  1585.             return '%s(pname=%s, aname="%s", typed=False, encoded=%s, %s)' % (self.klass, pname, self.getAttributeName(self.name), encoded, self._getOccurs())
  1586.         elif self.style == 'ref':
  1587.             return '%s(encoded=%s, %s)' % (self.klass, encoded, self._getOccurs())
  1588.         elif self.style == 'anyElement':
  1589.             return 'ZSI.TC.AnyElement(aname="%s", %s, %s)' % (self.getAttributeName(self.name), self._getOccurs(), self._getProcessContents())
  1590.         
  1591.         raise RuntimeError('Must set style(%s) for typecode list generation' % self.style)
  1592.  
  1593.  
  1594.  
  1595. class ElementSimpleTypeContainer(TypecodeContainerBase):
  1596.     type = DEC
  1597.     logger = _GetLogger('ElementSimpleTypeContainer')
  1598.     
  1599.     def _substitutionGroupTag(self):
  1600.         value = self.substitutionGroup
  1601.         if not value:
  1602.             return 'substitutionGroup = None'
  1603.         
  1604.         (nsuri, ncname) = value
  1605.         return 'substitutionGroup = ("%s","%s")' % (nsuri, ncname)
  1606.  
  1607.     
  1608.     def _setContent(self):
  1609.         aname = self.getAttributeName(self.name)
  1610.         pyclass = self.pyclass
  1611.         if pyclass == 'bool':
  1612.             pyclass = 'int'
  1613.         
  1614.         kw = KW.copy()
  1615.         kw.update(dict(aname = aname, ns = self.ns, name = self.name, substitutionGroup = self._substitutionGroupTag(), subclass = self.sKlass, literal = self.literalTag(), schema = self.schemaTag(), init = self.simpleConstructor(), klass = self.getClassName(), element = 'ElementDeclaration'))
  1616.         if self.local:
  1617.             kw['element'] = 'LocalElementDeclaration'
  1618.         
  1619.         element = (map,)((lambda i: i % kw), [
  1620.             '%(ID1)sclass %(klass)s(%(subclass)s, %(element)s):',
  1621.             '%(ID2)s%(literal)s',
  1622.             '%(ID2)s%(schema)s',
  1623.             '%(ID2)s%(init)s',
  1624.             '%(ID3)skw["pname"] = ("%(ns)s","%(name)s")',
  1625.             '%(ID3)skw["aname"] = "%(aname)s"'])
  1626.         app = element.append
  1627.         if pyclass is not None:
  1628.             app('%sclass IHolder(%s): typecode=self' % (ID3, pyclass))
  1629.             app('%skw["pyclass"] = IHolder' % ID3)
  1630.             app('%sIHolder.__name__ = "%s_immutable_holder"' % (ID3, aname))
  1631.         
  1632.         app('%s%s' % (ID3, self.simpleConstructor(self.sKlass)))
  1633.         self.writeArray(element)
  1634.  
  1635.     
  1636.     def setUp(self, tp):
  1637.         self._item = tp
  1638.         self.local = tp.isLocal()
  1639.         
  1640.         try:
  1641.             self.name = tp.getAttribute('name')
  1642.             self.substitutionGroup = tp.getAttribute('substitutionGroup')
  1643.             self.ns = tp.getTargetNamespace()
  1644.             qName = tp.getAttribute('type')
  1645.         except Exception:
  1646.             ex = None
  1647.             raise Wsdl2PythonError('Error occured processing element: %s' % tp.getItemTrace(), *ex.args)
  1648.  
  1649.         if qName is None:
  1650.             raise Wsdl2PythonError('Missing QName for element type attribute: %s' % tp.getItemTrace())
  1651.         
  1652.         tns = qName.getTargetNamespace()
  1653.         local = qName.getName()
  1654.         self.sKlass = BTI.get_typeclass(local, tns)
  1655.         if self.sKlass is None:
  1656.             raise Wsdl2PythonError('No built-in typecode for type definition("%s","%s"): %s' % (tns, local, tp.getItemTrace()))
  1657.         
  1658.         
  1659.         try:
  1660.             self.pyclass = BTI.get_pythontype(None, None, typeclass = self.sKlass)
  1661.         except Exception:
  1662.             ex = None
  1663.             raise Wsdl2PythonError('Error occured processing element: %s' % tp.getItemTrace(), *ex.args)
  1664.  
  1665.  
  1666.  
  1667.  
  1668. class ElementLocalSimpleTypeContainer(TypecodeContainerBase):
  1669.     type = DEC
  1670.     logger = _GetLogger('ElementLocalSimpleTypeContainer')
  1671.     
  1672.     def _setContent(self):
  1673.         kw = KW.copy()
  1674.         kw.update(dict(aname = self.getAttributeName(self.name), ns = self.ns, name = self.name, subclass = self.sKlass, literal = self.literalTag(), schema = self.schemaTag(), init = self.simpleConstructor(), klass = self.getClassName(), element = 'ElementDeclaration', baseinit = self.simpleConstructor(self.sKlass)))
  1675.         if self.local:
  1676.             kw['element'] = 'LocalElementDeclaration'
  1677.         
  1678.         element = (map,)((lambda i: i % kw), [
  1679.             '%(ID1)sclass %(klass)s(%(subclass)s, %(element)s):',
  1680.             '%(ID2)s%(literal)s',
  1681.             '%(ID2)s%(schema)s',
  1682.             '%(ID2)s%(init)s',
  1683.             '%(ID3)skw["pname"] = ("%(ns)s","%(name)s")',
  1684.             '%(ID3)skw["aname"] = "%(aname)s"',
  1685.             '%(ID3)s%(baseinit)s'])
  1686.         app = element.append
  1687.         pyclass = self.pyclass
  1688.         if pyclass is not None:
  1689.             if pyclass == 'bool':
  1690.                 pyclass = 'int'
  1691.             
  1692.             kw['pyclass'] = pyclass
  1693.             app('%(ID3)sclass IHolder(%(pyclass)s): typecode=self' % kw)
  1694.             app('%(ID3)sself.pyclass = IHolder' % kw)
  1695.             app('%(ID3)sIHolder.__name__ = "%(aname)s_immutable_holder"' % kw)
  1696.         
  1697.         self.writeArray(element)
  1698.  
  1699.     
  1700.     def _setup_pyclass(self):
  1701.         
  1702.         try:
  1703.             self.pyclass = BTI.get_pythontype(None, None, typeclass = self.sKlass)
  1704.         except Exception:
  1705.             ex = None
  1706.             raise Wsdl2PythonError('Error occured processing element: %s' % self._item.getItemTrace(), *ex.args)
  1707.  
  1708.  
  1709.     
  1710.     def setUp(self, tp):
  1711.         self._item = tp
  1712.         self.local = tp.isLocal()
  1713.         self.name = tp.getAttribute('name')
  1714.         self.ns = tp.getTargetNamespace()
  1715.         content = tp.content.content
  1716.         if content.isRestriction():
  1717.             
  1718.             try:
  1719.                 base = content.getTypeDefinition()
  1720.             except XMLSchema.SchemaError:
  1721.                 ex = None
  1722.                 base = None
  1723.  
  1724.             qName = content.getAttributeBase()
  1725.             if base is None:
  1726.                 self.sKlass = BTI.get_typeclass(qName[1], qName[0])
  1727.                 self._setup_pyclass()
  1728.                 return None
  1729.             
  1730.             raise Wsdl2PythonError, 'unsupported local simpleType restriction: %s' % tp.content.getItemTrace()
  1731.         
  1732.         if content.isList():
  1733.             
  1734.             try:
  1735.                 base = content.getTypeDefinition()
  1736.             except XMLSchema.SchemaError:
  1737.                 ex = None
  1738.                 base = None
  1739.  
  1740.             if base is None:
  1741.                 qName = content.getItemType()
  1742.                 self.sKlass = BTI.get_typeclass(qName[1], qName[0])
  1743.                 self._setup_pyclass()
  1744.                 return None
  1745.             
  1746.             raise Wsdl2PythonError, 'unsupported local simpleType List: %s' % tp.content.getItemTrace()
  1747.         
  1748.         if content.isUnion():
  1749.             raise Wsdl2PythonError, 'unsupported local simpleType Union: %s' % tp.content.getItemTrace()
  1750.         
  1751.         raise Wsdl2PythonError, 'unexpected schema item: %s' % tp.content.getItemTrace()
  1752.  
  1753.  
  1754.  
  1755. class ElementLocalComplexTypeContainer(TypecodeContainerBase, AttributeMixIn):
  1756.     type = DEC
  1757.     logger = _GetLogger('ElementLocalComplexTypeContainer')
  1758.     
  1759.     def _setContent(self):
  1760.         kw = KW.copy()
  1761.         
  1762.         try:
  1763.             kw.update(dict(klass = self.getClassName(), subclass = 'ZSI.TCcompound.ComplexType', element = 'ElementDeclaration', literal = self.literalTag(), schema = self.schemaTag(), init = self.simpleConstructor(), ns = self.ns, name = self.name, aname = self.getAttributeName(self.name), nsurilogic = self.nsuriLogic(), ofwhat = self.getTypecodeList(), atypecode = self.attribute_typecode, pyclass = self.getPyClass()))
  1764.         except Exception:
  1765.             ex = None
  1766.             args = [
  1767.                 'Failure processing an element w/local complexType: %s' % self._item.getItemTrace()]
  1768.             args += ex.args
  1769.             ex.args = tuple(args)
  1770.             raise 
  1771.  
  1772.         if self.local:
  1773.             kw['element'] = 'LocalElementDeclaration'
  1774.         
  1775.         element = [
  1776.             '%(ID1)sclass %(klass)s(%(subclass)s, %(element)s):',
  1777.             '%(ID2)s%(literal)s',
  1778.             '%(ID2)s%(schema)s',
  1779.             '%(ID2)s%(init)s',
  1780.             '%(ID3)s%(nsurilogic)s',
  1781.             '%(ID3)sTClist = [%(ofwhat)s]',
  1782.             '%(ID3)skw["pname"] = ("%(ns)s","%(name)s")',
  1783.             '%(ID3)skw["aname"] = "%(aname)s"',
  1784.             '%(ID3)s%(atypecode)s = {}',
  1785.             '%(ID3)sZSI.TCcompound.ComplexType.__init__(self,None,TClist,inorder=0,**kw)']
  1786.         for l in self.attrComponents:
  1787.             element.append('%(ID3)s' + str(l))
  1788.         
  1789.         element += self.getPyClassDefinition()
  1790.         element.append('%(ID3)sself.pyclass = %(pyclass)s' % kw)
  1791.         self.writeArray((map,)((lambda l: l % kw), element))
  1792.  
  1793.     
  1794.     def setUp(self, tp):
  1795.         self._item = tp
  1796.         self.name = tp.getAttribute('name')
  1797.         self.ns = tp.getTargetNamespace()
  1798.         self.local = tp.isLocal()
  1799.         complex = tp.content
  1800.         if complex is None:
  1801.             self.mgContent = ()
  1802.             return None
  1803.         
  1804.         if complex.content is None:
  1805.             self.mgContent = ()
  1806.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1807.             return None
  1808.         
  1809.         is_simple = complex.content.isSimple()
  1810.         if is_simple and complex.content.content.isExtension():
  1811.             self.mgContent = ()
  1812.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1813.             return None
  1814.         
  1815.         if is_simple and complex.content.content.isRestriction():
  1816.             self.mgContent = ()
  1817.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1818.             return None
  1819.         
  1820.         if is_simple:
  1821.             raise ContainerError, 'not implemented local complexType/simpleContent: %s' % tp.getItemTrace()
  1822.         
  1823.         is_complex = complex.content.isComplex()
  1824.         if is_complex and complex.content.content is None:
  1825.             self.mgContent = ()
  1826.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1827.             return None
  1828.         
  1829.         if is_complex and complex.content.content.isExtension() and complex.content.content.content is not None and complex.content.content.content.isModelGroup():
  1830.             self.mgContent = complex.content.content.content.content
  1831.             self.attrComponents = self._setAttributes(complex.content.content.getAttributeContent())
  1832.             return None
  1833.         
  1834.         if is_complex and complex.content.content.isRestriction() and complex.content.content.content is not None and complex.content.content.content.isModelGroup():
  1835.             self.mgContent = complex.content.content.content.content
  1836.             self.attrComponents = self._setAttributes(complex.content.content.getAttributeContent())
  1837.             return None
  1838.         
  1839.         if is_complex:
  1840.             self.mgContent = ()
  1841.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1842.             return None
  1843.         
  1844.         if complex.content.isModelGroup():
  1845.             self.mgContent = complex.content.content
  1846.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1847.             return None
  1848.         
  1849.         self.mgContent = ()
  1850.         self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1851.  
  1852.  
  1853.  
  1854. class ElementGlobalDefContainer(TypecodeContainerBase):
  1855.     type = DEC
  1856.     logger = _GetLogger('ElementGlobalDefContainer')
  1857.     
  1858.     def _substitutionGroupTag(self):
  1859.         value = self.substitutionGroup
  1860.         if not value:
  1861.             return 'substitutionGroup = None'
  1862.         
  1863.         (nsuri, ncname) = value
  1864.         return 'substitutionGroup = ("%s","%s")' % (nsuri, ncname)
  1865.  
  1866.     
  1867.     def _setContent(self):
  1868.         kw = KW.copy()
  1869.         
  1870.         try:
  1871.             kw.update(dict(klass = self.getClassName(), element = 'ElementDeclaration', literal = self.literalTag(), substitutionGroup = self._substitutionGroupTag(), schema = self.schemaTag(), init = self.simpleConstructor(), ns = self.ns, name = self.name, aname = self.getAttributeName(self.name), baseslogic = self.getBasesLogic(ID3), alias = NAD.getAlias(self.sKlassNS), subclass = type_class_name(self.sKlass)))
  1872.         except Exception:
  1873.             ex = None
  1874.             args = [
  1875.                 'Failure processing an element w/local complexType: %s' % self._item.getItemTrace()]
  1876.             args += ex.args
  1877.             ex.args = tuple(args)
  1878.             raise 
  1879.  
  1880.         if self.local:
  1881.             kw['element'] = 'LocalElementDeclaration'
  1882.         
  1883.         element = [
  1884.             '%(ID1)sclass %(klass)s(%(element)s):',
  1885.             '%(ID2)s%(literal)s',
  1886.             '%(ID2)s%(schema)s',
  1887.             '%(ID2)s%(substitutionGroup)s',
  1888.             '%(ID2)s%(init)s',
  1889.             '%(ID3)skw["pname"] = ("%(ns)s","%(name)s")',
  1890.             '%(ID3)skw["aname"] = "%(aname)s"',
  1891.             '%(baseslogic)s',
  1892.             '%(ID3)s%(alias)s.%(subclass)s.__init__(self, **kw)',
  1893.             '%(ID3)sif self.pyclass is not None: self.pyclass.__name__ = "%(klass)s_Holder"']
  1894.         self.writeArray((map,)((lambda l: l % kw), element))
  1895.  
  1896.     
  1897.     def setUp(self, element):
  1898.         self._item = element
  1899.         self.local = element.isLocal()
  1900.         self.name = element.getAttribute('name')
  1901.         self.substitutionGroup = element.getAttribute('substitutionGroup')
  1902.         self.ns = element.getTargetNamespace()
  1903.         tp = element.getTypeDefinition('type')
  1904.         self.sKlass = tp.getAttribute('name')
  1905.         self.sKlassNS = tp.getTargetNamespace()
  1906.  
  1907.  
  1908.  
  1909. class ComplexTypeComplexContentContainer(TypecodeContainerBase, AttributeMixIn):
  1910.     type = DEF
  1911.     logger = _GetLogger('ComplexTypeComplexContentContainer')
  1912.     
  1913.     def __init__(self, do_extended = False):
  1914.         TypecodeContainerBase.__init__(self, do_extended = do_extended)
  1915.  
  1916.     
  1917.     def setUp(self, tp):
  1918.         self._item = tp
  1919.         self.extType = None
  1920.         self.restriction = False
  1921.         self.extension = False
  1922.         self._kw_array = None
  1923.         self._is_array = False
  1924.         self.name = tp.getAttribute('name')
  1925.         self.ns = tp.getTargetNamespace()
  1926.         derivation = tp.content.content
  1927.         
  1928.         try:
  1929.             base = derivation.getTypeDefinition('base')
  1930.         except XMLSchema.SchemaError:
  1931.             ex = None
  1932.             base = None
  1933.  
  1934.         if base is None:
  1935.             base = derivation.getAttributeQName('base')
  1936.             if base is None:
  1937.                 raise ContainerError, 'Unsupported derivation: %s' % derivation.getItemTrace()
  1938.             
  1939.             if base != (SOAP.ENC, 'Array') and base != (SCHEMA.XSD3, 'anyType'):
  1940.                 raise ContainerError, 'Unsupported base(%s): %s' % (base, derivation.getItemTrace())
  1941.             
  1942.         
  1943.         if base == (SOAP.ENC, 'Array'):
  1944.             self.logger.debug('Derivation of soapenc:Array')
  1945.             self._is_array = True
  1946.             self._kw_array = {
  1947.                 'atype': None,
  1948.                 'id3': ID3,
  1949.                 'ofwhat': None }
  1950.             self.sKlass = BTI.get_typeclass(base[1], base[0])
  1951.             self.sKlassNS = base[0]
  1952.             for a in derivation.getAttributeContent():
  1953.                 if a.isReference() is False:
  1954.                     continue
  1955.                 
  1956.                 if a.getAttribute('ref') != (SOAP.ENC, 'arrayType'):
  1957.                     continue
  1958.                 
  1959.                 attr = a.getAttributeQName((WSDL.BASE, 'arrayType'))
  1960.                 if attr is None:
  1961.                     warnings.warn('soapenc:array derivation declares attribute reference ("%s","%s"), does not define attribute ("%s","%s")' % (SOAP.ENC, 'arrayType', WSDL.BASE, 'arrayType'))
  1962.                     break
  1963.                 
  1964.                 self._kw_array['atype'] = attr
  1965.                 qname = self._kw_array.get('atype')
  1966.                 if a is not None:
  1967.                     ncname = qname[1].strip('[]')
  1968.                     namespace = qname[0]
  1969.                     
  1970.                     try:
  1971.                         ofwhat = a.getSchemaItem(XMLSchema.TYPES, namespace, ncname)
  1972.                     except XMLSchema.SchemaError:
  1973.                         ex = None
  1974.                         ofwhat = None
  1975.  
  1976.                     if ofwhat is None:
  1977.                         self._kw_array['ofwhat'] = BTI.get_typeclass(ncname, namespace)
  1978.                     else:
  1979.                         self._kw_array['ofwhat'] = GetClassNameFromSchemaItem(ofwhat, do_extended = self.do_extended)
  1980.                     if self._kw_array['ofwhat'] is None:
  1981.                         raise ContainerError, 'For Array could not resolve ofwhat typecode(%s,%s): %s' % (namespace, ncname, derivation.getItemTrace())
  1982.                     
  1983.                     self.logger.debug('Attribute soapenc:arrayType="%s"' % str(self._kw_array['ofwhat']))
  1984.                     break
  1985.                     continue
  1986.             
  1987.         elif isinstance(base, XMLSchema.XMLSchemaComponent):
  1988.             self.sKlass = base.getAttribute('name')
  1989.             self.sKlassNS = base.getTargetNamespace()
  1990.         else:
  1991.             self.sKlass = base.getName()
  1992.             self.sKlassNS = base.getTargetNamespace()
  1993.         attrs = []
  1994.         if derivation.isRestriction():
  1995.             self.restriction = True
  1996.             self.extension = False
  1997.             if not derivation.getAttributeContent():
  1998.                 pass
  1999.             attrs += ()
  2000.         else:
  2001.             self.restriction = False
  2002.             self.extension = True
  2003.             if not tp.getAttributeContent():
  2004.                 pass
  2005.             attrs += ()
  2006.             if isinstance(derivation, XMLSchema.XMLSchemaComponent):
  2007.                 if not derivation.getAttributeContent():
  2008.                     pass
  2009.                 attrs += ()
  2010.             
  2011.         if attrs:
  2012.             self.extType = derivation
  2013.         
  2014.         if derivation.content is not None and derivation.content.isModelGroup():
  2015.             group = derivation.content
  2016.             if group.isReference():
  2017.                 group = group.getModelGroupReference()
  2018.             
  2019.             self.mgContent = group.content
  2020.         elif derivation.content:
  2021.             raise Wsdl2PythonError, 'expecting model group, not: %s' % derivation.content.getItemTrace()
  2022.         else:
  2023.             self.mgContent = ()
  2024.         self.attrComponents = self._setAttributes(tuple(attrs))
  2025.  
  2026.     
  2027.     def _setContent(self):
  2028.         kw = KW.copy()
  2029.         definition = []
  2030.         if self._is_array:
  2031.             if _is_xsd_or_soap_ns(self.sKlassNS) is False and self.sKlass == 'Array':
  2032.                 raise ContainerError, 'unknown type: (%s,%s)' % (self.sKlass, self.sKlassNS)
  2033.             
  2034.             definition += [
  2035.                 '%sclass %s(ZSI.TC.Array, TypeDefinition):' % (ID1, self.getClassName()),
  2036.                 '%s#complexType/complexContent base="SOAP-ENC:Array"' % ID2,
  2037.                 '%s%s' % (ID2, self.schemaTag()),
  2038.                 '%s%s' % (ID2, self.typeTag()),
  2039.                 '%s%s' % (ID2, self.pnameConstructor())]
  2040.             append = definition.append
  2041.             if self._kw_array.get('ofwhat') is None:
  2042.                 append("%s%s.__init__(self, None, None, pname=pname, childnames='item', undeclared=True, **kw)" % (ID3, self.sKlass))
  2043.             else:
  2044.                 append('%(id3)sofwhat = %(ofwhat)s(None, typed=False)' % self._kw_array)
  2045.                 append('%(id3)satype = %(atype)s' % self._kw_array)
  2046.                 append("%s%s.__init__(self, atype, ofwhat, pname=pname, childnames='item', **kw)" % (ID3, self.sKlass))
  2047.             self.writeArray(definition)
  2048.             return None
  2049.         
  2050.         definition += [
  2051.             '%sclass %s(TypeDefinition):' % (ID1, self.getClassName()),
  2052.             '%s%s' % (ID2, self.schemaTag()),
  2053.             '%s%s' % (ID2, self.typeTag()),
  2054.             '%s%s' % (ID2, self.pnameConstructor()),
  2055.             '%s%s' % (ID3, self.nsuriLogic()),
  2056.             '%sTClist = [%s]' % (ID3, self.getTypecodeList())]
  2057.         definition.append('%(ID3)sattributes = %(atc)s = attributes or {}' % {
  2058.             'ID3': ID3,
  2059.             'atc': self.attribute_typecode })
  2060.         isAnyType = (self.sKlassNS, self.sKlass) == (SCHEMA.XSD3, 'anyType')
  2061.         if isAnyType:
  2062.             del definition[0]
  2063.             definition.insert(0, '%sclass %s(ZSI.TC.ComplexType, TypeDefinition):' % (ID1, self.getClassName()))
  2064.             definition.insert(1, '%s#complexType/complexContent restrict anyType' % ID2)
  2065.         
  2066.         definition.append('%sif extend: TClist += ofwhat' % ID3)
  2067.         definition.append('%sif restrict: TClist = ofwhat' % ID3)
  2068.         if len(self.attrComponents) > 0:
  2069.             definition.append('%selse:' % ID3)
  2070.             for l in self.attrComponents:
  2071.                 definition.append('%s%s' % (ID4, l))
  2072.             
  2073.         
  2074.         if isAnyType:
  2075.             definition.append('%sZSI.TC.ComplexType.__init__(self, None, TClist, pname=pname, **kw)' % ID3)
  2076.             definition += self.getPyClassDefinition()
  2077.             kw['pyclass'] = self.getPyClass()
  2078.             definition.append('%(ID3)sself.pyclass = %(pyclass)s' % kw)
  2079.             self.writeArray(definition)
  2080.             return None
  2081.         
  2082.         definition.append('%s' % self.getBasesLogic(ID3))
  2083.         prefix = NAD.getAlias(self.sKlassNS)
  2084.         typeClassName = type_class_name(self.sKlass)
  2085.         if self.restriction:
  2086.             definition.append('%s%s.%s.__init__(self, pname, ofwhat=TClist, restrict=True, **kw)' % (ID3, prefix, typeClassName))
  2087.             definition.insert(1, '%s#complexType/complexContent restriction' % ID2)
  2088.             self.writeArray(definition)
  2089.             return None
  2090.         
  2091.         if self.extension:
  2092.             definition.append('%s%s.%s.__init__(self, pname, ofwhat=TClist, extend=True, attributes=attributes, **kw)' % (ID3, prefix, typeClassName))
  2093.             definition.insert(1, '%s#complexType/complexContent extension' % ID2)
  2094.             self.writeArray(definition)
  2095.             return None
  2096.         
  2097.         raise Wsdl2PythonError, 'ComplexContent must be a restriction or extension'
  2098.  
  2099.     
  2100.     def pnameConstructor(self, superclass = None):
  2101.         if superclass:
  2102.             return '%s.__init__(self, pname, ofwhat=(), extend=False, restrict=False, attributes=None, **kw)' % superclass
  2103.         
  2104.         return 'def __init__(self, pname, ofwhat=(), extend=False, restrict=False, attributes=None, **kw):'
  2105.  
  2106.  
  2107.  
  2108. class ComplexTypeContainer(TypecodeContainerBase, AttributeMixIn):
  2109.     type = DEF
  2110.     logger = _GetLogger('ComplexTypeContainer')
  2111.     
  2112.     def setUp(self, tp, empty = False):
  2113.         self._item = tp
  2114.         self.name = tp.getAttribute('name')
  2115.         self.ns = tp.getTargetNamespace()
  2116.         self.mixed = tp.isMixed()
  2117.         self.mgContent = ()
  2118.         self.attrComponents = self._setAttributes(tp.getAttributeContent())
  2119.         self._item = tp
  2120.         if empty:
  2121.             return None
  2122.         
  2123.         model = tp.content
  2124.         if model.isReference():
  2125.             model = model.getModelGroupReference()
  2126.         
  2127.         if model is None:
  2128.             return None
  2129.         
  2130.         if model.content is None:
  2131.             return None
  2132.         
  2133.         self.mgContent = model
  2134.  
  2135.     
  2136.     def _setContent(self):
  2137.         
  2138.         try:
  2139.             definition = [
  2140.                 '%sclass %s(ZSI.TCcompound.ComplexType, TypeDefinition):' % (ID1, self.getClassName()),
  2141.                 '%s%s' % (ID2, self.schemaTag()),
  2142.                 '%s%s' % (ID2, self.typeTag()),
  2143.                 '%s%s' % (ID2, self.pnameConstructor()),
  2144.                 '%s%s' % (ID3, self.nsuriLogic()),
  2145.                 '%sTClist = [%s]' % (ID3, self.getTypecodeList())]
  2146.         except Exception:
  2147.             ex = None
  2148.             args = [
  2149.                 'Failure processing %s' % self._item.getItemTrace()]
  2150.             args += ex.args
  2151.             ex.args = tuple(args)
  2152.             raise 
  2153.  
  2154.         definition.append('%s%s = attributes or {}' % (ID3, self.attribute_typecode))
  2155.         definition.append('%sif extend: TClist += ofwhat' % ID3)
  2156.         definition.append('%sif restrict: TClist = ofwhat' % ID3)
  2157.         if len(self.attrComponents) > 0:
  2158.             definition.append('%selse:' % ID3)
  2159.             for l in self.attrComponents:
  2160.                 definition.append('%s%s' % (ID4, l))
  2161.             
  2162.         
  2163.         definition.append('%sZSI.TCcompound.ComplexType.__init__(self, None, TClist, pname=pname, inorder=0, %s**kw)' % (ID3, self.getExtraFlags()))
  2164.         definition += self.getPyClassDefinition()
  2165.         kw = KW.copy()
  2166.         kw['pyclass'] = self.getPyClass()
  2167.         definition.append('%(ID3)sself.pyclass = %(pyclass)s' % kw)
  2168.         self.writeArray(definition)
  2169.  
  2170.     
  2171.     def pnameConstructor(self, superclass = None):
  2172.         if superclass:
  2173.             return '%s.__init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw)' % superclass
  2174.         
  2175.         return 'def __init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw):'
  2176.  
  2177.  
  2178.  
  2179. class SimpleTypeContainer(TypecodeContainerBase):
  2180.     type = DEF
  2181.     logger = _GetLogger('SimpleTypeContainer')
  2182.     
  2183.     def __init__(self):
  2184.         TypecodeContainerBase.__init__(self)
  2185.  
  2186.     
  2187.     def setUp(self, tp):
  2188.         raise NotImplementedError, 'abstract method not implemented'
  2189.  
  2190.     
  2191.     def _setContent(self, tp):
  2192.         raise NotImplementedError, 'abstract method not implemented'
  2193.  
  2194.     
  2195.     def getPythonType(self):
  2196.         pyclass = eval(str(self.sKlass))
  2197.         if issubclass(pyclass, ZSI.TC.String):
  2198.             return 'str'
  2199.         
  2200.         if issubclass(pyclass, ZSI.TC.Ilong) or issubclass(pyclass, ZSI.TC.IunsignedLong):
  2201.             return 'long'
  2202.         
  2203.         if issubclass(pyclass, ZSI.TC.Boolean) or issubclass(pyclass, ZSI.TC.Integer):
  2204.             return 'int'
  2205.         
  2206.         if issubclass(pyclass, ZSI.TC.Decimal):
  2207.             return 'float'
  2208.         
  2209.         if issubclass(pyclass, ZSI.TC.Gregorian) or issubclass(pyclass, ZSI.TC.Duration):
  2210.             return 'tuple'
  2211.         
  2212.  
  2213.     
  2214.     def getPyClassDefinition(self):
  2215.         definition = []
  2216.         pt = self.getPythonType()
  2217.         if pt is not None:
  2218.             definition.append('%sclass %s(%s):' % (ID3, self.getPyClass(), pt))
  2219.             definition.append('%stypecode = self' % ID4)
  2220.         
  2221.         return definition
  2222.  
  2223.  
  2224.  
  2225. class RestrictionContainer(SimpleTypeContainer):
  2226.     logger = _GetLogger('RestrictionContainer')
  2227.     
  2228.     def setUp(self, tp):
  2229.         self._item = tp
  2230.         if tp.content is None:
  2231.             raise Wsdl2PythonError, 'empty simpleType defintion: %s' % tp.getItemTrace()
  2232.         
  2233.         self.name = tp.getAttribute('name')
  2234.         self.ns = tp.getTargetNamespace()
  2235.         self.sKlass = None
  2236.         base = tp.content.getAttribute('base')
  2237.         if base is not None:
  2238.             
  2239.             try:
  2240.                 item = tp.content.getTypeDefinition('base')
  2241.             except XMLSchema.SchemaError:
  2242.                 ex = None
  2243.                 item = None
  2244.  
  2245.             if item is None:
  2246.                 self.sKlass = BTI.get_typeclass(base.getName(), base.getTargetNamespace())
  2247.                 if self.sKlass is not None:
  2248.                     return None
  2249.                 
  2250.                 raise Wsdl2PythonError('no built-in type nor schema instance type for base attribute("%s","%s"): %s' % (base.getTargetNamespace(), base.getName(), tp.getItemTrace()))
  2251.             
  2252.             raise Wsdl2PythonError, 'Not Supporting simpleType/Restriction w/User-Defined Base: %s %s' % (tp.getItemTrace(), item.getItemTrace())
  2253.         
  2254.         sc = tp.content.getSimpleTypeContent()
  2255.         if sc is not None:
  2256.             if sc.isSimple() is sc.isSimple() and sc.isLocal() is sc.isLocal():
  2257.                 pass
  2258.             elif sc.isLocal() is sc.isDefinition():
  2259.                 base = None
  2260.                 if sc.content.isRestriction() is True:
  2261.                     
  2262.                     try:
  2263.                         item = tp.content.getTypeDefinition('base')
  2264.                     except XMLSchema.SchemaError:
  2265.                         ex = None
  2266.  
  2267.                     if item is None:
  2268.                         base = sc.content.getAttribute('base')
  2269.                         if base is not None:
  2270.                             self.sKlass = BTI.get_typeclass(base.getTargetNamespace(), base.getName())
  2271.                             return None
  2272.                         
  2273.                         raise Wsdl2PythonError, 'Not Supporting simpleType/Restriction w/User-Defined Base: ' % item.getItemTrace()
  2274.                     
  2275.                     raise Wsdl2PythonError, 'Not Supporting simpleType/Restriction w/User-Defined Base: ' % item.getItemTrace()
  2276.                 
  2277.                 if sc.content.isList() is True:
  2278.                     raise Wsdl2PythonError, 'iction base in subtypes: %s' % sc.getItemTrace()
  2279.                 
  2280.                 if sc.content.isUnion() is True:
  2281.                     raise Wsdl2PythonError, 'could not get restriction base in subtypes: %s' % sc.getItemTrace()
  2282.                 
  2283.                 return None
  2284.             
  2285.         raise Wsdl2PythonError, 'No Restriction @base/simpleType: %s' % tp.getItemTrace()
  2286.  
  2287.     
  2288.     def _setContent(self):
  2289.         definition = [
  2290.             '%sclass %s(%s, TypeDefinition):' % (ID1, self.getClassName(), self.sKlass),
  2291.             '%s%s' % (ID2, self.schemaTag()),
  2292.             '%s%s' % (ID2, self.typeTag()),
  2293.             '%s%s' % (ID2, self.pnameConstructor())]
  2294.         if self.getPythonType() is None:
  2295.             definition.append('%s%s.__init__(self, pname, **kw)' % (ID3, self.sKlass))
  2296.         else:
  2297.             definition.append('%s%s.__init__(self, pname, pyclass=None, **kw)' % (ID3, self.sKlass))
  2298.             definition += self.getPyClassDefinition()
  2299.             kw = KW.copy()
  2300.             kw['pyclass'] = self.getPyClass()
  2301.             definition.append('%(ID3)sself.pyclass = %(pyclass)s' % kw)
  2302.         self.writeArray(definition)
  2303.  
  2304.  
  2305.  
  2306. class ComplexTypeSimpleContentContainer(SimpleTypeContainer, AttributeMixIn):
  2307.     type = DEF
  2308.     logger = _GetLogger('ComplexTypeSimpleContentContainer')
  2309.     
  2310.     def setUp(self, tp):
  2311.         self._item = tp
  2312.         simple = tp.content
  2313.         dv = simple.content
  2314.         self.name = tp.getAttribute('name')
  2315.         self.ns = tp.getTargetNamespace()
  2316.         self.content.attributeContent = dv.getAttributeContent()
  2317.         base = dv.getAttribute('base')
  2318.         if base is not None:
  2319.             self.sKlass = BTI.get_typeclass(base[1], base[0])
  2320.             if not self.sKlass:
  2321.                 self.sKlass = base[1]
  2322.                 self.sKlassNS = base[0]
  2323.             
  2324.             self.attrComponents = self._setAttributes(self.content.attributeContent)
  2325.             return None
  2326.         
  2327.         raise Wsdl2PythonError, 'simple content derivation bad base attribute: ' % tp.getItemTrace()
  2328.  
  2329.     
  2330.     def _setContent(self):
  2331.         if type(self.sKlass) in (types.ClassType, type):
  2332.             definition = [
  2333.                 '%sclass %s(%s, TypeDefinition):' % (ID1, self.getClassName(), self.sKlass),
  2334.                 '%s# ComplexType/SimpleContent derivation of built-in type' % ID2,
  2335.                 '%s%s' % (ID2, self.schemaTag()),
  2336.                 '%s%s' % (ID2, self.typeTag()),
  2337.                 '%s%s' % (ID2, self.pnameConstructor()),
  2338.                 '%sif getattr(self, "attribute_typecode_dict", None) is None: %s = {}' % (ID3, self.attribute_typecode)]
  2339.             for l in self.attrComponents:
  2340.                 definition.append('%s%s' % (ID3, l))
  2341.             
  2342.             definition.append('%s%s.__init__(self, pname, **kw)' % (ID3, self.sKlass))
  2343.             if self.getPythonType() is not None:
  2344.                 definition += self.getPyClassDefinition()
  2345.                 kw = KW.copy()
  2346.                 kw['pyclass'] = self.getPyClass()
  2347.                 definition.append('%(ID3)sself.pyclass = %(pyclass)s' % kw)
  2348.             
  2349.             self.writeArray(definition)
  2350.             return None
  2351.         
  2352.         definition = [
  2353.             '%sclass %s(TypeDefinition):' % (ID1, self.getClassName()),
  2354.             '%s# ComplexType/SimpleContent derivation of user-defined type' % ID2,
  2355.             '%s%s' % (ID2, self.schemaTag()),
  2356.             '%s%s' % (ID2, self.typeTag()),
  2357.             '%s%s' % (ID2, self.pnameConstructor()),
  2358.             '%s%s' % (ID3, self.nsuriLogic()),
  2359.             '%s' % self.getBasesLogic(ID3),
  2360.             '%sif getattr(self, "attribute_typecode_dict", None) is None: %s = {}' % (ID3, self.attribute_typecode)]
  2361.         for l in self.attrComponents:
  2362.             definition.append('%s%s' % (ID3, l))
  2363.         
  2364.         definition.append('%s%s.%s.__init__(self, pname, **kw)' % (ID3, NAD.getAlias(self.sKlassNS), type_class_name(self.sKlass)))
  2365.         self.writeArray(definition)
  2366.  
  2367.     
  2368.     def getPyClassDefinition(self):
  2369.         definition = []
  2370.         pt = self.getPythonType()
  2371.         if pt is not None:
  2372.             definition.append('%sclass %s(%s):' % (ID3, self.getPyClass(), pt))
  2373.             if self.metaclass is not None:
  2374.                 definition.append('%s__metaclass__ = %s' % (ID4, self.metaclass))
  2375.             
  2376.             definition.append('%stypecode = self' % ID4)
  2377.         
  2378.         return definition
  2379.  
  2380.  
  2381.  
  2382. class UnionContainer(SimpleTypeContainer):
  2383.     type = DEF
  2384.     logger = _GetLogger('UnionContainer')
  2385.     
  2386.     def __init__(self):
  2387.         SimpleTypeContainer.__init__(self)
  2388.         self.memberTypes = None
  2389.  
  2390.     
  2391.     def setUp(self, tp):
  2392.         self._item = tp
  2393.         if tp.content.isUnion() is False:
  2394.             raise ContainerError, 'content must be a Union: %s' % tp.getItemTrace()
  2395.         
  2396.         self.name = tp.getAttribute('name')
  2397.         self.ns = tp.getTargetNamespace()
  2398.         self.sKlass = 'ZSI.TC.Union'
  2399.         self.memberTypes = tp.content.getAttribute('memberTypes')
  2400.  
  2401.     
  2402.     def _setContent(self):
  2403.         definition = [
  2404.             '%sclass %s(%s, TypeDefinition):' % (ID1, self.getClassName(), self.sKlass),
  2405.             '%smemberTypes = %s' % (ID2, self.memberTypes),
  2406.             '%s%s' % (ID2, self.schemaTag()),
  2407.             '%s%s' % (ID2, self.typeTag()),
  2408.             '%s%s' % (ID2, self.pnameConstructor()),
  2409.             '%s%s' % (ID3, self.pnameConstructor(self.sKlass))]
  2410.         self.writeArray(definition)
  2411.  
  2412.  
  2413.  
  2414. class ListContainer(SimpleTypeContainer):
  2415.     type = DEF
  2416.     logger = _GetLogger('ListContainer')
  2417.     
  2418.     def setUp(self, tp):
  2419.         self._item = tp
  2420.         if tp.content.isList() is False:
  2421.             raise ContainerError, 'content must be a List: %s' % tp.getItemTrace()
  2422.         
  2423.         self.name = tp.getAttribute('name')
  2424.         self.ns = tp.getTargetNamespace()
  2425.         self.sKlass = 'ZSI.TC.List'
  2426.         self.itemType = tp.content.getAttribute('itemType')
  2427.  
  2428.     
  2429.     def _setContent(self):
  2430.         definition = [
  2431.             '%sclass %s(%s, TypeDefinition):' % (ID1, self.getClassName(), self.sKlass),
  2432.             '%sitemType = %s' % (ID2, self.itemType),
  2433.             '%s%s' % (ID2, self.schemaTag()),
  2434.             '%s%s' % (ID2, self.typeTag()),
  2435.             '%s%s' % (ID2, self.pnameConstructor()),
  2436.             '%s%s' % (ID3, self.pnameConstructor(self.sKlass))]
  2437.         self.writeArray(definition)
  2438.  
  2439.  
  2440.